Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set autoUpload option to Jquery File Upload

i'm trying to set autoUpload flag to jQuery File Upload. So i try editing jquery.fileupload.js in this way:

(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,
            .
            .
            .

and main.js in this way:

$(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,
            .
            .
            .

i can see through this

<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>

that start button appears, so o.options.autoUpload is false, but i set it to true. What can i do? in which way i can set autoupload to upload image directly when it is selected? thanks!!!!

like image 259
Jayyrus Avatar asked May 17 '12 16:05

Jayyrus


1 Answers

i solved taking the original example downloaded from the plugin site and i change flag autoUpload:true and it works :)

like image 63
Jayyrus Avatar answered Oct 01 '22 20:10

Jayyrus