You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 12:13:05