通过Node.js SDK上传文件至S3后文件为空的问题求助
通过Node.js SDK上传文件至S3后文件为空的问题求助
大家好,我现在碰到个棘手的问题,想请教下各位:
我们有一个S3存储桶,用来上传文件。用户上传文件后,能成功传到S3桶里,但打开一看,文件居然是完全空白的。
我贴一下后端的代码片段,麻烦帮忙看看哪里可能出问题了:
// Importing modules import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3'; // Setting up S3 client const s3 = new S3Client({ credentials: { accessKeyId: process.env.ACCESS_KEY_ID as string, secretAccessKey: process.env.SECRET_ACCESS_KEY as string, }, region: s3Info.S3_REGION, }); const pdfContent = Buffer.from(file[0].buffer); const params = { Bucket: s3Info.S3_BUCKET_NAME, Key: getFilePath(fileName), Body: pdfContent, ContentType: file[0].mimetype, }; // Uploading the document. const command = new PutObjectCommand(params); const res = await s3.send(command); return fileName;
目前看起来所有流程都走通了,没有报错,但传到S3里的文件就是空白的,实在找不到原因,求各位大佬指点迷津!
备注:内容来源于stack exchange,提问作者Not A Robot
相关产品推荐
相关产品推荐

