所以我使用AWS S3 Javascript SDK上传多个文件。 以下代码效果很好,但我确实有一个问题。进度的function (evt)
是异步调用的,我无法获取它所调用的文件名。 evt
不包含文件名。有没有办法知道?
如何将文件名输出到控制台(我显示>>> I NEED THE FILENAME HERE <<<
)
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (files[i]) {
var params = {Key: file.name, ContentType: file.type, Body: file};
bucket.upload(params).on('httpUploadProgress', function(evt) {
console.log("Uploaded " + >>> I NEED THE FILENAME HERE <<< + " " + parseInt((evt.loaded * 100) / evt.total)+'%');
}).send(function(err, data) {
//alert("File uploaded successfully -- " + err);
});
}
}
答案 0 :(得分:0)
evt.key - &gt;应该给出正在上传的文件名...... !!!
已编辑:
这是我用于托管上传的完整代码
app.post('/uploadLargeFile',upload.array('file', 20),function(req,res){
console.log("received File")
var file = req.files;
for(var i=0;i<req.files.length;i++){
var file = req.files[i];
uploadLargeFiles(file);
}
})
function uploadLargeFiles(file){
var params={
ACL :'public-read',
Body : new Buffer(file.buffer),
Bucket:'ascendon1',
ContentType:file.mimetype,
Key:file.originalname
}
var managedUpload = new AWS.S3.ManagedUpload({
params:params
});
managedUpload.on('httpUploadProgress', function(progress) {
console.log(progress);
});
managedUpload.send(function(err, data) {
console.log(err, data);
});
}