【问题标题】:Blueimp jquery file upload plugin throwing error after uploading 100% is done to rackspace cloud storageBlueimp jquery 文件上传插件在上传 100% 到 rackspace 云存储后抛出错误
【发布时间】:2013-11-03 20:03:25
【问题描述】:

我一直在尝试从我的网站将文件上传到机架空间存储。我已按照以下 api 指南创建将文件上传到 rackspace 的表单。 http://docs.rackspace.com/files/api/v1/cf-devguide/content/FormPost-d1a555.html 第 7.2、7.2.1 和 7.2.2 节

如果我进行正常的表单提交,它完全可以正常工作。该文件被上传到机架空间存储并返回状态 201 和空白消息。我检查了容器中的文件并成功上传。

但现在问题来了,当我尝试使用 Blueimp jQuery 文件上传插件集成进度条时。

这是我初始化文件上传插件的代码

$(function () {
'use strict';

// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({maxChunkSize: 10000000});




if (window.location.hostname === 'blueimp.github.com') {
    // Demo settings:
    $('#fileupload').fileupload('option', {
        url: '//jquery-file-upload.appspot.com/',
        maxFileSize: 5000000,
        acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
        process: [
            {
                action: 'load',
                fileTypes: /^image\/(gif|jpeg|png)$/,
                maxFileSize: 20000000 // 20MB
            },
            {
                action: 'resize',
                maxWidth: 1440,
                maxHeight: 900
            },
            {
                action: 'save'
            }
        ]
    });
    // Upload server status check for browsers with CORS support:
    if ($.support.cors) {
        $.ajax({
            url: '//jquery-file-upload.appspot.com/',
            type: 'HEAD'
        }).fail(function () {
            $('<span class="alert alert-error"/>')
                .text('Upload server currently unavailable - ' +
                        new Date())
                .appendTo('#fileupload');
        });
    }
} else {
    // Load existing files:
    console.log("mukibul");
    $('#fileupload').each(function () {
        var that = this;
        console.log("result1");
        $.getJSON(this.action, function (result) {

            if (result && result.length) {
                console.log("result");
                console.log(result);
                $(that).fileupload('option', 'done')
                    .call(that, null, {result: result});
            }
        });
    });
}});

这是上传文件的网络表单

<form id="fileupload" action="https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_4d6c7b53-7b5a-458c-8a2d-957971f293bb/tranceyatralocal/${sessionScope.tyUser.userID}/${albumDetails.albumId}" method="POST" enctype="multipart/form-data">
    <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
     <input type="hidden" name="redirect" value="http://localhost:8080/impianlabs/home/uploadResponse.htm" />
        <input type="hidden" name="max_file_size" value="${max_file_size}" />
        <input type="hidden" name="max_file_count" value="10" />
        <input type="hidden" name="expires" value="${expires}" />
        <input type="hidden" name="signature" value="${hmac}" />
    <div class="row fileupload-buttonbar" style="margin:10px;">
        <div class="span7" style="">
            <!-- The fileinput-button span is used to style the file input field as button -->
            <span class="btn btn-success fileinput-button">
                <i class="icon-plus icon-white"></i>
                <span>Add files...</span>
                 <input type="file" name="files[]" multiple>
            </span>
            <button type="submit" class="btn btn-primary start">
                <i class="icon-upload icon-white"></i>
                <span>Start upload</span>
            </button>
            <button type="reset" class="btn btn-warning cancel">
                <i class="icon-ban-circle icon-white"></i>
                <span>Cancel upload</span>
            </button>
            <button type="button" class="btn btn-danger delete">
                <i class="icon-trash icon-white"></i>
                <span>Delete</span>
            </button>
            <input type="checkbox" class="toggle">
        </div>
        <!-- The global progress information -->
        <div class="span5 fileupload-progress fade">
            <!-- The global progress bar -->
            <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                <div class="bar" style="width:0%;"></div>
            </div>
            <!-- The extended global progress information -->
            <div class="progress-extended">&nbsp;</div>
        </div>
    </div>
    <!-- The loading indicator is shown during file processing -->
    <div class="fileupload-loading"></div>
    <br>
   <!--  <div>
        <ul id="filePreview">

        </ul>
    </div> -->




    <!-- The table listing the files available for upload/download -->





    <table role="presentation" class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>
</form>

当我上传任何文件时,它开始正常上传,进度开始按预期显示。在 chrome Inspect->Network 选项卡中,我可以看到对机架空间服务器的两个请求。一个是返回 200 的方法 OPTIONS,另一个是 POST 方法,它一直处于待处理状态,直到进度条达到 100%,但一旦达到 100%,POST 方法的状态就会更改为已取消,并且 jquery 文件上传插件在网页。我无法理解为什么插件会抛出错误。我检查了容器,发现文件上传成功。

我使用 curl 在机架空间中设置了 CORS 所需的所有标头。但不确定我做错了什么。任何解决问题的帮助将不胜感激。

注意:我正在为应用程序使用 spring mvc。

谢谢, 穆基布尔

【问题讨论】:

  • Mukibul - 我正在研究一个示例以尝试使其正常工作。我刚刚完成了表单设置并正确上传。我正在添加 BlueImp 插件。
  • OP 我想我已经了解了问题所在。对于初学者,示例代码在实际输入上调用 .fileupload() 方法。您在父表单上调用它。接下来,您的 $.getJSON() 方法是最初到达端点的方法,导致 401 Unauthorized。我会在这方面做更多工作,并尽快为您发布答案。
  • 非常感谢克里斯·拉斯科。期待您的回答。
  • OP 我现在可以复制您的问题,并且我看到了您的确切行为。我仍在努力寻找解决方案。

标签: javascript jquery file-upload blueimp rackspace


【解决方案1】:

目前,Cloud Files 和底层 Openstack Swift 组件确实支持 POST 上传,因为您已成功使用(文档 herehere)。不幸的是,由于响应中缺少标头,似乎有一个 known issue 阻止 CORS 正常工作。

更改已合并到 master,但尚未部署到 Rackspace 的 Cloud Files 运行版本。我向我们的 CF 团队询问了修复此问题的时间表,以便我们能够就此达成真正的解决方案。

更新:该脚本无法在 Chrome 中为我上传,但在 Firefox 中有效。 Chrome 报告 POST 已如您所述被取消,但 Firefox 完成它并获得 HTTP 303 响应以及预期的重定向 URI,并且文件存在于容器中。我正在查看插件的代码,以了解它如何处理响应中的成功/失败。

【讨论】:

  • 非常感谢克里斯的更新。如果您找到任何解决方法,请告诉我。我已经尝试过使用其他 jquery 文件上传器,例如 valums-file-uploader.github.io/file-uploader 。但是有了这个,responseJSON 也是一个空白对象。
  • 克里斯,找到任何替代解决方案的运气好吗?我在使用 amazon s3 时遇到了同样的问题。尝试在 fileuploaddone 事件上修改结果对象,但没有成功。 data.result 对象总是为空。我正在使用 forceIframeTransport:true 选项。
【解决方案2】:

刚刚从 Rackspace 发现此合并不在路线图中,目前也没有进行测试。我不认为这会在不久的将来出现。

希望有一天他们会实施它。现在,我只需要在控制器中覆盖页面的标题,然后再将其提供给浏览器。

【讨论】:

  • 我与技术支持进行了交谈。很高兴知道您为 Rackspace 工作,但技术支持似乎不知道发生了什么。
  • 大公司;很多活动部件。 :) 我会标记这个并密切关注它,希望它会在某个时候得到解决。
  • 谢谢克里斯。我希望收到您的来信。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-13
  • 1970-01-01
  • 1970-01-01
  • 2014-06-18
  • 1970-01-01
相关资源
最近更新 更多