简体   繁体   English

使用SDK和Uploadify将文件上载到Amazon S3时显示的上载进度不正确

[英]Incorrect upload progress shown when uploading file to Amazon S3 using SDK and Uploadify

My ASP.NET MVC (C#) application is using Uploadify to upload files to Amazon S3 using the SDK for .NET, but it shows incorrect upload progress. 我的ASP.NET MVC(C#)应用程序使用Uploadify使用SDK for .NET将文件上传到Amazon S3,但它显示错误的上载进度。

When I upload a file directly to our server using Uploadify it works fine. 当我使用Uploadify将文件直接上传到我们的服务器时,它工作正常。 However, when I upload a file using Amazon S3 TransferUtility.Upload method, the progress bar shows 100% completion quickly, but I need to wait for a long time to attain Uploadify's onComplete event. 但是,当我使用Amazon S3 TransferUtility.Upload方法上传文件时,进度条快速显示100%完成,但我需要等待很长时间才能获得Uploadify的onComplete事件。 My code is shown below. 我的代码如下所示。

C# code: C#代码:

using (transferUtility = new TransferUtility(AWSAccessKey, AWSSecretKey))
{
    try
    {
        TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();

        request.WithBucketName(AWSBucket)
            .WithKey(folderKey)
            .WithTimeout(5 * 60 * 1000)
            .WithInputStream(uploadFileStream);

        request.WithCannedACL(S3CannedACL.PublicRead);

        transferUtility.Upload(request);
    }                
    catch (AmazonS3Exception amazonS3Exception)
    {
        throw amazonS3Exception;
    }
}

JavaScript code: JavaScript代码:

jQuery(document).ready(function () {
    var allowdfileext='*.doc;*.docx;*.pdf;'
    var extarray=allowdfileext.split(';');

    jQuery('#proposalUploadFile').uploadify({
        'uploader': '/Content/uploadify/uploadify.swf',
        'script': '/File/Upload',
        'folder': '/uploads',
        'buttonImg':'/Content/uploadify/upload-file.jpg',
        'cancelImg': '/Content/uploadify/cancel.png',
        'auto': true,            
        'height': '25',
        'width': '95', 
        'wmode':'transparent',
        'sizeLimit': '20971520',
        'onComplete': fileUploaded,
        'multi': false,
        'scriptData': {
            'saveToFolder': 'Temp',
            'fileextension':'*.doc;*.docx;*.pdf;',
            'subdomain':'qa','saveInLocal':'True'
        },
        'fileExt':'*.doc;*.docx;*.pdf;',
        'fileDesc':'Files (*.doc;*.docx;*.pdf;)',
        'onAllComplete': fileUploadCompleted,
        'onError' : function(event, ID, fileObj, errorObj) {
            var r = '<br />ERROR: ';

            switch(errorObj.info) {
                case 405:
                    r += 'Invalid file type.';
                    break;
                case 406:
                    r += 'Some other error.';
                    break;
                default:
                    r += 'Some other error.';
                    break;
            }       
        }
    });
});

Why isn't the progress bar updating like I'm expecting it to? 为什么进度条不像我期望的那样更新?

Essentially there are two uploads happening. 基本上有两个上传发生。 Once from the web page to your server and once from your server to the cloud. 一旦从网页到您的服务器,一次从您的服务器到云端。

What you are seeing is the upload progress from the webpage to your upload handler. 您看到的是从网页到上传处理程序的上传进度。 The browser only knows about the data being sent from the client to your server, not the data being sent from your server to S3. 浏览器只知道从客户端发送到服务器的数据,而不是从服务器发送到S3的数据。

Without doing some pretty complex server work, getting the accurate upload progress value is not possible. 如果不做一些非常复杂的服务器工作,就无法获得准确的上传进度值。 I would recommend either firing off a background thread to handle the upload to S3 or setting the progress to something less than 100% until the complete callback is fired. 我建议要么触发后台线程来处理上传到S3,要么将进度设置为小于100%,直到完成回调。

How would the TransferUtility communicate from the server side back to the swf client? TransferUtility如何从服务器端回复到swf客户端? I would assume that the upload from the client to the server would be reflected in the progress bar. 我假设从客户端到服务器的上传将反映在进度条中。 Next, the server transfer to S3 would be (much slower than writing to a local file), which wouldn't be reported to the client (swf). 接下来,服务器转移到S3将(比写入本地文件慢得多),这将不会报告给客户端(swf)。 That would account for the delay between the upload reaching 100% and then having to wait for the page to respond. 这将导致上传达到100%之间的延迟,然后必须等待页面响应。

Usually, there is a config section where you can set the time to update the state of the progress in the state provider. 通常,有一个配置部分,您可以在其中设置更新状态提供程序中的进度状态的时间。 In your case I assume there must be something like that. 在你的情况下,我认为必须有类似的东西。

In neatUpload this config is set by stateMergeIntervalSeconds . 在neatUpload中,此配置由stateMergeIntervalSeconds设置。 I hope this help. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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