2012-05-17 24 views
5

मैं स्वत: अपलोड फ्लैग को jQuery File Upload पर सेट करने का प्रयास कर रहा हूं। इस तरह सेJquery फ़ाइल अपलोड करने के लिए autoUpload विकल्प को सेट करने के लिए कैसे करें

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

और main.js: तो मैं इस तरह से संपादन jquery.fileupload.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, 
      . 
      . 
      . 

मैं इस

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

कि शुरू बटन है, इसलिए ओ के माध्यम से देख सकते हैं। options.autoUpload false है, लेकिन मैं इसे true पर सेट करता हूं। मैं क्या कर सकता हूं? जिस तरह से मैं चयनित होने पर सीधे छवि अपलोड करने के लिए स्वत: अपलोड कर सकता हूं? धन्यवाद !!!!

उत्तर

13

मैं प्लगइन साइट से डाउनलोड मूल उदाहरण लेने हल और मैं झंडा autoUpload:true बदल सकते हैं और यह :)

+2

धन्यवाद जैक काम करता है। आपके जवाब ने वास्तव में मेरी मदद की। मैंने बस $ ('# fileupload') जोड़ा। फ़ाइल अपलोड ('विकल्प', {autoUpload: true \t}); main.js के लिए और यह काम किया। सावधान रहें यदि इसे (window.location.hostname === 'blueimp.github.com') ब्लॉक में न डालें। – clone45

+0

यह मेरे लिए बिल्कुल काम नहीं करेगा। AutoUpload विकल्प केवल 'jquery.fileupload-ui.js' में दिखाई देता है, इसलिए मैंने इसे बिना किसी सफलता के' सत्य 'में बदल दिया। मैंने clone45 की विधि भी कोशिश की और यह भी काम नहीं किया। कोई विचार? – vertigoelectric

+1

मुझे अपना खुद का समाधान मिला। उस पृष्ठ पर जहां आप अपलोड छोड़ते हैं, मैंने एक 'सेट इंटरवल' जोड़ा जो कि प्रत्येक 'आधा' बटन मौजूद है या नहीं, यह देखने के लिए प्रत्येक आधे सेकेंड की जांच करता है। अब तक यह बहुत अच्छा काम करता प्रतीत होता है। – vertigoelectric

संबंधित मुद्दे

 संबंधित मुद्दे