天天看點

aws sdk之nodejs s3

upload 和putObject有什麼差別,同樣是上傳或新增一個object

upload适用于比較大的檔案,putObject适用于小的檔案内容,upload支援自定義多線程并發上傳

function syncFile(file) {
	var bodyStream = fs.createReadStream(file.absolute_path, {encoding: 'utf8'});
    var options = {
        Bucket    : config.aws.bucket,
        Key    : config.aws.key_prefix + "/" + file.relative_path, 
        ContentLength : file.size,
        Body          : bodyStream
    };

    s3.putObject(options, function(err, data) {
    	if (err) {
	  		console.log("upload err,filepath:" + file.absolute_path);
	  		console.log(err);
	  		process.exit();
	  		return false;
	  	}
	  	bodyStream.destroy();
    });
}
           

報錯:

2016-08-22 13:01:52 [ERROR] sync logs failed,err:BadRequest: An error occurred when parsing the HTTP request., file:/home/web/xxxx,file count:160

如果一個檔案正在上傳,又重複執行了上傳操作,就會報上面這個錯誤。

繼續閱讀