简体   繁体   English

如何使用putObject从Node.js将CSV文件上传到AWS S3?

[英]How can I use putObject to upload a csv file to AWS S3 from Nodejs?

I tried to directly upload the file stream as a parameter, but it didn't work. 我尝试直接将文件流作为参数上传,但是没有用。

var param = {
    Bucket: 'sql-dev',
    Key: 'Report',
    Body: new Buffer(fs.createWriteStream('./temp/ALL.csv'))
};  
s3bucket.putObject(param, function(err, data){
    if(err) console.log(err);
    else console.log(data);
});

How do I use that? 如何使用?

You need to use a read stream, not a write stream. 您需要使用读取流,而不是写入流。 Also, you shouldn't be wrapping your stream inside a Buffer. 另外,您不应该将流包装在Buffer中。

var param = {
    Bucket: 'sql-dev',
    Key: 'Report',
    Body: fs.createReadStream('./temp/ALL.csv')
};  
s3bucket.putObject(param, function(err, data){
    if(err) console.log(err);
    else console.log(data);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 AWS SDK(在 Node.js 中)中的 putObject() 将文件从 HTTP 响应正文上传到 S3? - How can I upload a file from an HTTP response body to S3 using putObject() from the AWS SDK (in Node.js)? Nodejs - 如何将文件从 req 上传到 aws s3 - Nodejs - how to upload file from req to aws s3 如何使用Node.js将单个文件上传到AWS s3上的多个路径? - How can I upload single file to multiple path on aws s3 using nodejs? 如何使用 NodeJS 在 S3 存储桶上上传 CSV 文件? - How to Upload CSV file on S3 Bucket using NodeJS? 将csv文件直接从服务器上传到aws s3存储桶 - Upload csv file to aws s3 bucket directly from a server S3 putObject 没有使用 nodejs 将我的文件从 EFS 上传到 S3 Lambda - S3 putObject isn't uploading my file to S3 from EFS using nodejs Lambda 我如何从特定的 ec2 实例获得对 s3 的 putobject 访问权限 - How can i get putobject access to s3 from specific ec2 instance 如何让 AWS S3 上传可重用的 function 并在我选择的任何文件中使用来自 AWS 的回调? - How to make AWS S3 upload a reusable function and use the callback from AWS in any file of my choosing? 使用 nodejs 将 CSV javascript 对象上传到 AWS S3 - Upload CSV javascript object to AWS S3 using nodejs S3:如何使用aws-sdk在nodejs中使用S3上传大文件 - S3 : How to upload a large file using S3 in nodejs using aws-sdk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM