我正在使用dropzone.js将文件上传到 Azure 云存储桶。
文件正在上传到存储桶,但当我下载它们时,它们已损坏。
我的拖放区设置如下:
var printDropzone = new Dropzone("#printDropZone", { method: 'post', maxFiles: 1 });
printDropzone.on('sending', function (file, xhr, formData) {
xhr.setRequestHeader("x-ms-blob-type", "BlockBlob");
xhr.setRequestHeader('Content-Length', file.size);
});
printDropzone.on('processing', function (file, xhr) {
$.ajax({
url: '/api/sas',
type: 'GET',
async: false,
success: function (response) {
var timeStamp = Math.floor(Date.now() / 1000);
upload = timeStamp + '-' + file.name;
printDropzone.options.url = response.HostingSite + '/' +upload + response.Token;
printDropzone.options.method = 'put';
}
});
});
请求如下所示:
Accept:application/json
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:23684
Content-Type:multipart/form-data; boundary=---- WebKitFormBoundaryALPTivVAxkgUv5lv
DNT:1
Host:somehost.net
Origin:http://localhost:2130
Referer:http://localhost:2130/
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36
x-ms-blob-type:BlockBlob
X-Requested-With:XMLHttpRequest
我到处都找过了。我没有分块上传,所有内容似乎都在那里,但无论我上传什么类型的文件,它都会在我重新下载时损坏。
最佳答案
尝试将 multipart 设置为 false。
printDropzone.on('processing', function (file, xhr) {
$.ajax({
url: '/api/sas',
type: 'GET',
async: false,
success: function (response) {
var timeStamp = Math.floor(Date.now() / 1000);
upload = timeStamp + '-' + file.name;
printDropzone.options.url = response.HostingSite + '/' +upload + response.Token;
printDropzone.options.method = 'put';
printDropzone.options.multipart = false;
}
});
关于javascript - 通过 AJAX 上传到 Azure 云存储的文件已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31641908/