uploads: fix errors not being shown for failed disk uploads.

Fix the error message not being shown if an upload from disk failed for
whatever reason, for example because it was a corrupt or unsupported file.
This commit is contained in:
evazion
2022-02-01 13:39:08 -06:00
parent c4852b3486
commit 38ebda7415
2 changed files with 9 additions and 7 deletions

View File

@@ -33,9 +33,7 @@
<div class="dz-upload h-1" data-dz-uploadprogress></div> <div class="dz-upload h-1" data-dz-uploadprogress></div>
</div> </div>
<div class="dz-error-message"> <div class="dz-error-message" data-dz-errormessage></div>
<p data-dz-errormessage></p>
</div>
</div> </div>
</template> </template>
</div> </div>

View File

@@ -64,7 +64,7 @@ export default class FileUploadComponent {
dropzone.on("success", file => { dropzone.on("success", file => {
this.$dropzone.addClass("success"); this.$dropzone.addClass("success");
let upload = JSON.parse(file.xhr.response) let upload = JSON.parse(file.xhr.response)
location.href = `/uploads/${upload.id}`; this.pollStatus(upload);
}); });
dropzone.on("error", (file, msg) => { dropzone.on("error", (file, msg) => {
@@ -85,11 +85,14 @@ export default class FileUploadComponent {
e.preventDefault(); e.preventDefault();
} }
onSubmit(e) {
let upload = e.originalEvent.detail[0];
this.pollStatus(upload);
}
// Called after the upload is submitted via AJAX. Polls the upload until it // Called after the upload is submitted via AJAX. Polls the upload until it
// is complete, then redirects to the upload page. // is complete, then redirects to the upload page.
async onSubmit(e) { async pollStatus(upload) {
let upload = e.originalEvent.detail[0];
this.$component.find("progress").removeClass("hidden"); this.$component.find("progress").removeClass("hidden");
this.$component.find("input").attr("disabled", "disabled"); this.$component.find("input").attr("disabled", "disabled");
@@ -101,6 +104,7 @@ export default class FileUploadComponent {
if (upload.status === "completed") { if (upload.status === "completed") {
location.href = `/uploads/${upload.id}`; location.href = `/uploads/${upload.id}`;
} else { } else {
this.$dropzone.removeClass("success");
this.$component.find("progress").addClass("hidden"); this.$component.find("progress").addClass("hidden");
this.$component.find("input").removeAttr("disabled"); this.$component.find("input").removeAttr("disabled");