aws-sdk-js icon indicating copy to clipboard operation
aws-sdk-js copied to clipboard

File is not uploaded sometime

Open shaangidwani opened this issue 2 years ago • 4 comments

Describe the bug

The user is trying to upload one file at that time we have captured the event progress and based on that we display the status of the file upload.

Sometimes when the user uploads the file, it shows 100%, but the file is not uploaded on the server without giving any error by the AWS js Utility.

Due to this issue, the system and user think the file is uploaded but has not been uploaded.

Expected Behavior

If the file is not uploaded on S3 it should give the proper error.

Current Behavior

Currently its not giving any error and file is not uploaded on s3

Reproduction Steps

Its random issue we have try after sometime same file is uploaded successfully without any issue with same source code

Possible Solution

Gives error so that system will not processed further and provide error to user.

Additional Information/Context

Here is the code which we are using :

bucket.upload(params, options).on('httpUploadProgress', function (evt) {
            $(".progress-bar").show();
            var Perc = parseInt((evt.loaded * 100) / evt.total);
            $(".progress-bar").html(Perc + '%');
            $(".progress-bar").attr("aria-valuenow", Perc);
            $(".progress-bar").attr("aria-valuenow", Perc);
            $(".progress-bar").css("width", Perc + '%');
            if (Perc == 100) {
                //toastrSuccess("File uploaded successfully.");
                $(".progress-bar").html(0 + '%');
                $(".progress-bar").attr("aria-valuenow", 0);
                $(".progress-bar").attr("aria-valuenow", 0);
                $(".progress-bar").css("width", 0 + '%');
                $(".progress-bar").hide();                
            }
        }).send(function (err, data) {           
            if (!err) {
                // success
            }
            else {
                alert(err + "Something went wrong while uploading file. Please try again.");
                
            }
        });

SDK version used

AWS SDK for JavaScript v2.727.1

Environment details (OS name and version, etc.)

Windows OS

shaangidwani avatar Feb 09 '23 12:02 shaangidwani

I think we are seeing this issue as well.

await s3.upload(params).promise()

corymhall avatar Feb 10 '23 15:02 corymhall

Hi @shaangidwani, thanks for opening this issue. I tried to reproduce this but as you said seems it may happen sporadically. I will investigate this further to see if I can find a reproducible scenario that I can use to root cause the issue.

Thanks!

yenfryherrerafeliz avatar Feb 19 '23 00:02 yenfryherrerafeliz

I've got the exact same issue using serverless framework and uploading to s3. Works most of the time then sometimes it won''t work, couple retries later it works.

KieranDaviesV avatar May 05 '23 10:05 KieranDaviesV

That's kinda wierd , never had this issue while uploading to s3:


const S3 = require('aws-sdk/clients/s3')
const bucketName = process.env.AWS_BUCKET_NAME
const region = process.env.AWS_BUCKET_REGION
const accessKeyId = process.env.AWS_ACCESS_KEY
const secretAccessKey = process.env.AWS_SECRET_KEY

const s3 = new S3({
  region,
  accessKeyId,
  secretAccessKey
})

//pass the file by using multer middleware 
function uploadFile(file) {
  const fileStream = fs.createReadStream(file.path)

  const uploadParams = {
    Bucket: bucketName,
    Body:fileStream ,
    Key: file.filename
  }

  return s3.upload(uploadParams).promise()
}

zakhaev26 avatar Jun 16 '23 14:06 zakhaev26