上传文件stream到S3没有文件和内存

我试图从一个string创build一个csv并将其上传到我的S3存储桶。 我不想写一个文件。 我希望这一切都在记忆中。

我不想从文件中读取我的stream。 我想用文件做一个stream。 我想这个方法createReadStream ,而不是一个文件,我想传递一个string与我的stream的内容。

 var AWS = require('aws-sdk'), zlib = require('zlib'), fs = require('fs'); s3Stream = require('s3-upload-stream')(new AWS.S3()), // Set the client to be used for the upload. AWS.config.loadFromPath('./config.json'); // Create the streams var read = fs.createReadStream('/path/to/a/file'); var upload = s3Stream.upload({ "Bucket": "bucket-name", "Key": "key-name" }); // Handle errors. upload.on('error', function (error) { console.log(error); }); upload.on('part', function (details) { console.log(details); }); upload.on('uploaded', function (details) { console.log(details); }); read.pipe(upload); 

你可以创build一个ReadableStream并将你的string直接推送给它,然后可以被你的s3Stream实例使用。

 const Readable = require('stream').Readable let data = 'this is your data' let read = new Readable() read.push(data) // Push your data string read.push(null) // Signal that you're done writing // Create upload s3Stream instance and attach listeners go here read.pipe(upload)