2015-01-09 35 views
1

在NodeJS中,我從文件上傳的數據塊中分段保存文件。我想通過做新的緩衝區()然後將其上傳到亞馬遜s3NodeJs - 如何將數據塊轉換爲新的緩衝區?

這將工作,如果只有一個塊,但當有多個,我不知道如何做新的緩衝區()

目前我的解決方案是將數據塊寫入我自己的服務器上的真實文件,然後將該文件的PATH發送到Amazon s3。

如何跳過文件創建步驟並實際發送Amazon S3的緩衝區?

回答

0

我猜你需要使用流-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); 
    }); 

}; 
+0

這不會解決我的問題,因爲亞馬遜S3擁有500 MB的最低限額。我的大塊大小約爲2 MB。不管我是否使用這種方法,我仍然必須將我的塊組合成至少5 MB的塊。 有沒有辦法將塊組合成一個更大的塊或創建一個緩衝區多個塊? – Mcope

相關問題