我正在使用blueimp's jQuery File Upload插件的API将大型和小型文件上传到S3。我正在向处理S3上传的服务器发送PUT请求。我的代码如下:
// Initialize the file upload so we don't get errors
angular.element(document.querySelector('#add-file-btn')).fileupload({
url: '/test'
});
// Set up options for file upload
angular.element(document.querySelector('#add-file-btn')).fileupload(
'option',
{
url: '/temp', // Temporary, replaced in handleAdd
type: 'PUT',
dataType: 'json',
dropZone: 'dropzone-area',
acceptFileTypes: /(\.|\/)(csv|jpe?g|png)$/i, // Only accept csv files (images enabled for testing)
progressInterval: 2000, // Check progress every 2 seconds
autoUpload: true,
paramName: 'files',
formData: {
fileSize: null
},
beforeSend: function(xhr, data) {
// Set request headers
xhr.setRequestHeader('Authorization', 'bearer ' + storageService.get('token'));
xhr.setRequestHeader('Accept', 'application/json ');
},
multipart: true,
add: handleAdd,
submit: handleSubmit,
progress: handleProgress ,
processdone: handleProcessDone,
processfail: handleProcessFail,
start: handleStart,
stop: handleStop,
done: handleDone
}
);
当我上传一个小文件(200 KB)时,文件已成功上传。当我尝试上传一个大文件(2.66 GB)并记录我的handleProgress()函数中显示的进度时,我看到进度挂起几分钟,然后它会快速记录最后一个进度,所以它就在它之后100%完成我看到已返回504网关超时错误。
function handleProgress(e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
data.files[0].progress = progress;
console.log(progress)
}
后端人说他的代码适用于通过命令行上传大文件,所以我们试图弄清楚它为什么不能在浏览器中工作。有任何想法吗?我知道504错误应该只是一个服务器端问题,但是它在为CLI工作时感到困惑...