2016-01-05 47 views
0

如何獲取隊列中文件大小的總數。我想允許用戶只上傳100 MB文件,所以現在如果任何一個文件選擇大於100MB的文件,此代碼工作良好,但是當我選擇60-60 mb的兩個文件的總數是120 MB時,這不會顯示任何錯誤。任何想法相同如何在plupload中獲取隊列的總文件大小而不是單個文件大小

$(function() { 
    $("#uploader").plupload({ 
     runtimes : 'html5,flash,silverlight', 
     url : 'http://<?=$bucket?>.s3.amazonaws.com/', 

     multipart: true, 
     multipart_params: { 
      'key': '<?=$filepath?>${filename}', // use filename as a key 
      'Filename': '${filename}', // adding this to keep consistency across the runtimes 
      'acl': 'public-read', 
      'Content-Type': 'application/octet-stream', 
      'AWSAccessKeyId' : '<?=$accessKeyId?>',  
      'policy': '<?=$policy?>', 
      'signature': '<?=$signature?>' 
     }, 

     // optional, but better be specified directly 
     file_data_name: 'file', 
     filters : { 
      // Maximum file size 
      max_file_size : '100mb' 
      // Specify what files to browse for 
      //mime_types: [ 
      // {title : "Image files", extensions : "jpg,jpeg"} 
      //] 
     }, 
     // Flash settings 
     flash_swf_url : 'js/Moxie.swf', 
     // Silverlight settings 
     silverlight_xap_url : 'js/Moxie.xap' 
    }); 

}); 
+0

如果你找到答案代碼工作,請把它標記爲正確答案,這樣其他可以看到那個信息。此代碼每天都在我的生產環境中工作。 –

回答

1

試試這個:

/* Check the queue after files added to see if the total size of all files combined exceeds allowed limit. */ 
var maxQueueSize = 681574400; // Size in bytes. This is set to 650MB. 
uploader.bind('QueueChanged', function(up) { 
    if(uploader.total.size > maxQueueSize) { 
     alert("Total size of all files exceeds disc capacity! Remove some files!"); 
    } 
}); 

在這裏找到它: http://www.plupload.com/punbb/viewtopic.php?id=757