gpt4 book ai didi

javascript - NodeJs - 如何将数据 block 转换为新的缓冲区?

转载 作者:太空宇宙 更新时间:2023-11-03 22:36:22 26 4
gpt4 key购买 nike

在 NodeJS 中,我有来自文件上传的数据 block ,这些数据 block 将文件保存为多个部分。我想通过执行 new Buffer() 来转换它,然后将其上传到 Amazon s3

如果只有一个 block ,那么这会起作用,但是当有多个 block 时,我不知道如何执行 new Buffer()

目前我的解决方案是将数据 block 写入我自己的服务器上的真实文件中,然后将该文件的 PATH 发送到 Amazon s3。

如何跳过文件创建步骤并将缓冲区实际发送到 Amazon s3?

最佳答案

我猜你需要使用streaming-s3

var streamingS3 = require('streaming-s3');
var uploadFile = function (fileReadStream, awsHeader, cb) {

//set options for the streaming module
var options = {
concurrentParts: 2,
waitTime: 20000,
retries: 2,
maxPartSize: 10 * 1024 * 1024
};
//call stream function to upload the file to s3
var uploader = new streamingS3(fileReadStream, aws.accessKey, aws.secretKey, awsHeader, options);
//start uploading
uploader.begin();// important if callback not provided.

// handle these functions
uploader.on('data', function (bytesRead) {
console.log(bytesRead, ' bytes read.');
});

uploader.on('part', function (number) {
console.log('Part ', number, ' uploaded.');
});

// All parts uploaded, but upload not yet acknowledged.
uploader.on('uploaded', function (stats) {
console.log('Upload stats: ', stats);
});

uploader.on('finished', function (response, stats) {
console.log(response);
cb(null, response);
});

uploader.on('error', function (err) {
console.log('Upload error: ', err);
cb(err);
});

};

关于javascript - NodeJs - 如何将数据 block 转换为新的缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27853143/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com