2012-05-17 29 views
5

Tôi đang cố đặt cờ tự động tải lên thành jQuery File Upload. Vì vậy, tôi cố gắng chỉnh sửa jquery.fileupload.js theo cách này:Cách đặt tùy chọn tự động tải lên tệp Jquery Tải lên

(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 theo cách này:

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

tôi có thể nhìn xuyên qua này

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

rằng bắt đầu nút xuất hiện, vì vậy o. options.autoUpload là false, nhưng tôi đặt nó là true. Tôi có thể làm gì? theo cách nào tôi có thể đặt tự động tải lên để tải lên hình ảnh trực tiếp khi được chọn? cảm ơn !!!!

Trả lời

13

tôi đã giải quyết lấy ví dụ gốc được tải xuống từ trang plugin và tôi thay đổi cờ autoUpload:true và nó hoạt động :)

+2

Cảm ơn Jack. Câu trả lời của bạn thực sự đã giúp tôi. Tôi chỉ cần thêm $ ('# fileupload'). Fileupload ('option', {autoUpload: true \t}); với main.js và nó hoạt động. Hãy cẩn thận không đặt nó trong khối if (window.location.hostname === 'blueimp.github.com'). – clone45

+0

Điều này hoàn toàn không hiệu quả với tôi. Tùy chọn autoUpload chỉ xuất hiện trong 'jquery.fileupload-ui.js', vì vậy tôi đã thay đổi nó thành' true' mà không thành công. Tôi cũng đã thử phương pháp của clone45 và điều đó cũng không có tác dụng. Ý tưởng nào? – vertigoelectric

+1

Tôi tìm thấy giải pháp của riêng mình. Trên trang nơi bạn thả các video tải lên, tôi đã thêm 'setInterval' kiểm tra mỗi nửa giây để xem nút 'Bắt ​​đầu' có tồn tại không và nhấp vào nút đó. Cho đến nay nó dường như làm việc tuyệt vời. – vertigoelectric

Các vấn đề liên quan