Reputation: 17522
On a Node.js server I am uploading a stream to S3. Here is a simplified example:
import S3 from "aws-sdk/clients/s3"
const s3 = new S3({ accessKeyId, secretAccessKey, region })
async function uploadStream(key, stream) {
const upload = s3.upload({
Body: stream,
Bucket: clientFiles,
Key: key,
})
const result = await upload.promise()
return result // { Bucket, ETag, Key, Location }
}
Since I am using a stream, I don't know the total size when the upload is initiated, and the upload result doesn't give me anything more than Bucket, ETag, Key, & Location values.
How can I get the total size of the uploaded stream?
Upvotes: 1
Views: 199
Reputation: 1795
How about use ManagedUpload
and httpUploadProgress
?
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3/ManagedUpload.html#httpUploadProgress-event
async function uploadStream(key, stream) {
const upload = new AWS.S3.ManagedUpload({
params: {
Body: stream,
Bucket: clientFiles,
Key: key
}
});
upload.on("httpUploadProgress", function(progress) {
console.log(progress.total);
});
...
Upvotes: 1