简体   繁体   中英

Amazon S3 File Upload Progress Never Reaches 100%

I am using an Azure Function and the AWS .NET libraries to upload blobs to S3 from a stream. During this transfer I subscribe to the UploadProgressEvent which receives the bytes transferred and the percent complete.

           uploadRequest.UploadProgressEvent +=
new EventHandler<UploadProgressArgs>
    (uploadRequest_UploadPartProgressEvent);

In this event I use the entity framework to log the bytes and the percent to a database so I can see what is going on.

      public void uploadRequest_UploadPartProgressEvent(object sender, UploadProgressArgs e)
{
AppDbContext db = new AppDbContext (ConfigurationManager.ConnectionStrings["name"].ConnectionString);
        BlobTriggerLog r = new BlobTriggerLog() { blobName = this.blobName, started = DateTime.Now, awsPercent = e.PercentDone, awsBytesCopied = e.TransferredBytes };
        db.BlobTriggerLogs.Add(r);
         db.SaveChanges();
        transferPercent = e.PercentDone;
}

THE ISSUE: When I run the function locally everything consistently goes to plan, I get a log going from 0-100% complete showing that my event is fired to the end of the upload. However, when I run the function in Azure, although the upload completes successfully, the event stops being triggered before it gets to 100%. For large files (100Mb+) it often gets to 80-98% complete before logging stops. The function is marked as executed without errors in Azure.

Has anyone else experienced this problem?

I have a block in my calling function to wait until the upload reaches 100%.

            while(aws.transferPercent != 100)
        {
            Task.Delay(TimeSpan.FromSeconds(0.5)).Wait();
        }

aws.transfer percent is the variable in the same class as my progress event.

That might be becoz you are having bunch of logic in your callback,

  public void uploadRequest_UploadPartProgressEvent(object sender, UploadProgressArgs e)
{
        // Just perform a log on e.PercentDone and you can see 100% out there.
}

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM