0

我想创建一个节点后端节点js文件上传到S3或本地

文件可以被上传到Amazon S3的桶或根据配置本地服务器上的文件上传服务。

据我了解

我可以使用S3-载流上传到S3桶。我有以下问题

  1. 在NPM mpdule页的示例

    变种读取= fs.createReadStream( './路径/到/ file.ext');

该流是使用本地文件创建的。我如何从客户端读取输入流并将其传送到s3。我能用这个强大的吗?

的文件大小可能会非常大。上传服务应该是生产就绪服务多个请求。 指向我的使用案例的任何文档或指南将是非常有帮助的

回答

1

如果想坚持S3上传流,我建议你使用打杂:

https://www.npmjs.com/package/busboy

busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { 
    // Instead of the events 'data' and 'end' as the show in the documentation 
    // you can just pipe the file to the upload from s3-upload-stream 

    file.pipe(upload); 
}); 

我抢这一块的代码从上面的链接。你从busboy得到的文件是你的可读流。

希望它有帮助。

相关问题