Nikolay Traykov
Nikolay Traykov

Reputation: 1695

How to delete or update files already uploaded on the server via Dropzone.js

I have announcement object that can contain multiple images. I managed to create the form for uploading files via dropzone. Now I want to give access to the author of the announcement to edit it, which means to edit the images as well. To edit the images means to re-order them, to remove some of them (or all of them) or to add more.

What I wanted to do is to load the announcement object and add the images to the dropzone object so that when the user clicks the submit button all images to be sent along the rest announcement's data. In other words to enqueue the images to dropzone and to submit them again. This way on server side I can see which files are new, which are missing, what the order is etc.

What I did so far:

TypeError: Argument 2 of FormData.append does not implement interface Blob

I saw an answer on stackoverflow about this, but this seems to be a very complicated workaround to me for the simple operation I need to do.

Is there any other simpler solution for this purpose? How do you edit the images that you upload to the server? What would you do to re-order the images, or to add/delete images to/from the queue?

Thanks in advance!

Upvotes: 0

Views: 4214

Answers (1)

Nikolay Traykov
Nikolay Traykov

Reputation: 1695

I managed to do it myself. I am using PHP, so I will explain it in PHP terms.

CLIENT: Basically I check whether I am in update or create mode. If I am in update mode, I load the existing pictures and show them to the user exactly as described in the dropzone's FAQ.

I also keep an array called order with all the images. I update this array always when an action to the images is done - adding a new one, deleting, re-ordering. It doesn't matter whether I am in update or create mode. When I submit the form, I send this array as well.

The only difference is that if I have new images added, I call dropzone.processQueue() else I call $.post(). In both cases I am senging the order array along with the other form data.

SERVER: If new images are added, I get them from the $_FILES array. In any case I get the order from the order post param.

I won't delete this question with the hope it will help anyone in the future. If any questions, please ask.

Upvotes: 1

Related Questions