3

I have a problem with my dropzone,

$(".js-example-basic-multiple").select2(); Dropzone.options.dropZone = { //options here maxFilesize: 2, addRemoveLinks: true, removedfile: function(file) { var name = file.name; $.ajax({ type: 'POST', url: host+'upload/unfile', data: "id="+name, dataType: 'html' }); var _ref; return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0; //console.log(); }, init: function() { this.on("maxfilesexceeded", function(file){ alert("No more files please!"); }); } } 

My problem is, when a file fails to upload, it still shows the preview images, so i need that file to be removed automatically when these file fails to upload, how can I do that??

1
  • Tq for smarx, sorry for my bad english Commented Jun 14, 2017 at 4:34

2 Answers 2

10

I think, if I understand you correctly, you can just delete the image with this code:

Dropzone.options.dropZone = { ... , error: function(file, message, xhr) { $(file.previewElement).remove(); }, ... } 

Just read the documentation again. This code is from the docs:

myDropzone.on("error", function(file) { myDropzone.removeFile(file); }); 

Please let me know, if it works in your case.

Sign up to request clarification or add additional context in comments.

1 Comment

Only the latter worked for me. The first one just removes the preview. then my dropzone, drop-area got shrunk.
-1

When connect error is "xhr.ontimeout", function "error:" don't run.

I need (paste next to "init:"):

sending: function(file, xhr, formData) { //Execute on case of timeout only xhr.ontimeout = function(e) { alert('connection interrupted'); }; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.