Reputation: 77
I can already upload my files to s3. But I want to get the progress loaded in each file.
bucket.upload(params, function(err, data){
console.log("File Uploaded Successfully");
}).on('httpUploadProgress', function(progress){
console.log(progress.loaded / progress.total * 100);}
The problem with this code is. The progress returns some data but it does not identify that this data is for that single file.
Is there any way to find out if the return progress is for that single data?.
Upvotes: 0
Views: 2455
Reputation: 5112
this works for me.
S3.upload(params, options, function (err, data) {
if (err) {
reject("error");
}
alert("Successfully Uploaded!");
}).on("httpUploadProgress", (progress) => {
let uploaded = parseInt((progress.loaded * 100) / progress.total);
this.setState({
progress: uploaded,
uploadText: "Uploading...",
uploading: true,
});
});
Upvotes: 0
Reputation: 31
For those who came across the same issue. There's no need to hack the code actually. Just use this
in the upload progress callback.
s3.upload(params, function (err, data) {
...
}).on('httpUploadProgress', function(progress) {
// Here you can use `this.body` to determine which file this particular
// event is related to and use that info to calculate overall progress.
});
I've posted an issue in the AWS SDK JS repo, and maybe there will be a better solution over time.
Upvotes: 1
Reputation: 357
Sorry for late answer (I am not even sure if you still need one).
I had the same problem, I forked their repo on github and made the solution myself.
here is alink of the updated aws-sdk-js repo that does what you need.
https://github.com/mohamed-kamal/aws-sdk-js-upload-progress
hope it helps.
Upvotes: 0