[英]No response with Dropzone.js vdropzone-success () using chunked uploads
我在 Vue 中使用 Dropzone.js。 我正在嘗試使用 v-on:vdropzone-success 連接到服務器響應。 如果 uploadFile 是單個塊,一切都按預期工作,但如果有多個塊,則響應返回空。有人解決了這個問題嗎? 我錯過了一些明顯的東西嗎? 謝謝!
<dropzone ref="myVueDropzone"
id="customdropzone"
:options="dropzoneOptions"
v-on:vdropzone-file-added="addFileTypeBorder"
v-on:vdropzone-upload-progress="updateProgressBar"
v-on:vdropzone-removed-file="removeFile"
v-on:vdropzone-success="addAnalysisId"
:include-styling="false">
</dropzone>
功能:
addAnalysisId: function(file, response){
console.log(response)
},
這是服務器響應在我的檢查器中的樣子。 每個塊作為單獨的請求提交。 顯示了最終請求。 所有其他塊以塊 # 響應。 督察形象
我看到這是一個舊線程,但我在這里碰到了尋找答案。 所以查看庫源代碼,成功時沒有返回第二個參數。 只有文件的一個實例。
我發現在返回的對象中有一個 xhr 屬性。 在那里您可以找到來自服務器的響應。 所以在你的情況下:
addAnalysisId: function(file){
console.log(file.xhr.response);
},
然后,您可以根據需要解析響應並使用它。
要檢查塊的響應,您應該在 dropzone.js 中添加此代碼:(搜索“200”,您會找到)
if (!(200 <= xhr.status && xhr.status < 300)) {
this._handleUploadError(files, xhr, response);
} else {
if (files[0].upload.chunked) {
files[0].upload.finishedChunkUpload(this._getChunk(files[0], xhr));
} else {
this._finished(files, response, e);
}
}
到 :
if (!(200 <= xhr.status && xhr.status < 300)) {
this._handleUploadError(files, xhr, response);
} else {
//check response
var status=JSON.parse(response)['status'];
if(status==='error'){
this._handleUploadError(files, xhr, response);
} else {
if (files[0].upload.chunked) {
files[0].upload.finishedChunkUpload(this._getChunk(files[0], xhr));
} else {
this._finished(files, response, e);
}
}
}
_handleUploadError 將再次上傳失敗的塊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.