如何将autoUpload选项设置为Jquery File Upload

Jac*_*rky 6 upload jquery file

我正在尝试将autoUpload标志设置为jQuery文件上传.所以我尝试jquery.fileupload.js以这种方式编辑:

(function (factory) {
    'use strict';
    if (typeof define === 'function' && define.amd) {
        // Register as an anonymous AMD module:
        define([
            'jquery',
            'jquery.ui.widget'
        ], factory);
    } else {
        // Browser globals:
        factory(window.jQuery);
    }
}(function ($) {
    'use strict';

    // The FileReader API is not actually used, but works as feature detection,
    // as e.g. Safari supports XHR file uploads via the FormData API,
    // but not non-multipart XHR file uploads:
    $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader);
    $.support.xhrFormDataFileUpload = !!window.FormData;

    // The fileupload widget listens for change events on file input fields defined
    // via fileInput setting and paste or drop events of the given dropZone.
    // In addition to the default jQuery Widget methods, the fileupload widget
    // exposes the "add" and "send" methods, to add or directly send files using
    // the fileupload API.
    // By default, files added via file input selection, paste, drag & drop or
    // "add" method are uploaded immediately, but it is possible to override
    // the "add" callback option to queue file uploads.
    $.widget('blueimp.fileupload', {

        options: {
            // The namespace used for event handler binding on the dropZone and
            // fileInput collections.           
            // If not set, the name of the widget ("fileupload") is used.
            namespace: undefined,
            autoUpload:true,
            .
            .
            .
Run Code Online (Sandbox Code Playgroud)

main.js以这种方式:

$(function () {
    'use strict';

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

    // Enable iframe cross-domain access via redirect option:
    $('#fileupload').fileupload(
        'option',
        'redirect',
        window.location.href.replace(
            /\/[^\/]*$/,
            '/cors/result.html?%s'
        )
    );

    if (window.location.hostname === 'blueimp.github.com') {
        // Demo settings:
        $('#fileupload').fileupload('option', {
            url: '//jquery-file-upload.appspot.com/',
            maxFileSize: 5000000,
            autoUpload:true,
            .
            .
            .
Run Code Online (Sandbox Code Playgroud)

我可以看透这个

<td class="start">{% if (!o.options.autoUpload) { %}
    <button class="btn btn-primary">
        <i class="icon-upload icon-white"></i>
        <span>{%=locale.fileupload.start%}</span>
    </button>
{% } %}</td>
Run Code Online (Sandbox Code Playgroud)

出现启动按钮,所以o.options.autoUpload是false,但我把它设置为true.我能做什么?以哪种方式我可以设置autoupload直接上传图像?谢谢!!!!

Jac*_*rky 15

我解决了从插件网站下载的原始示例,我改变标志autoUpload:true,它的工作原理:)

  • 谢谢杰克.你的回答真的帮助了我.我只是添加了$('#fileupload').fileupload('option',{autoUpload:true}); 到main.js,它工作.注意不要将它放在if(window.location.hostname ==='blueimp.github.com')块中. (2认同)
  • 谢谢,它在Rails 4中运行良好,只是我添加了"$('#fileupload').fileupload('option',{autoUpload:true});" (2认同)