2013-10-11 33 views
5

我正在通過JavaScript代碼上傳文件到服務器。我注意到不同的瀏覽器正在發送不同大小的字節。正如您在下面的圖片中看到的,Internet Explorer發送的是小字節,但Chrome和Firefox發送更大的字節。爲什麼Javascript通過瀏覽器上傳塊大小?

  1. 我使用XMLHttpRequest上傳文件。我可以爲所有瀏覽器設置標準的 上傳字節嗎?因爲不同大小的流量在某些瀏覽器上給出了 錯誤。 Http錯誤是404.13。
  2. 我將web.config文件配置爲<requestLimits maxAllowedContentLength="1073741824">(1GB),但是當我使用Firefox和Chrome上傳大文件(500 Mb)時,服務器發出system.OutOfMemoryException。 Internet Explorer工作正常。

火狐

enter image description here

的Internet Explorer

enter image description here

enter image description here

+1

複製? http://stackoverflow.com/questions/19332692/does-javascript-features-change-by-browser –

回答

1

我不知道爲什麼它不同,但是你可以根據瀏覽器改變你的行爲(與你在問題中提出的標準化相反)。

請參考moo uploader中的代碼作爲例子。

來源:https://github.com/juanparati/MooUpload/blob/master/Source/MooUpload.js

// Get slice method 
    if (file.mozSlice)   // Mozilla based 
     chunk = file.mozSlice(start, total) 
    else if (file.webkitSlice) // Chrome, Safari, Konqueror and webkit based 
     chunk = file.webkitSlice(start, total); 
    else      // Opera and other standards browsers 
     chunk = file.slice(start, total)