Add existing image files in Dropzone

Add existing image files in Dropzone

July 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Add existing image files in Dropzone

Handling Existing Image Files in DropzoneJS

The Current Setup

You’re using DropzoneJS for image uploads within an HTML form that contains various fields. To ensure all images are processed together when the form is submitted, you’ve set autoProcessQueue to false and manually trigger processing on the submit button click event.

Here’s your current configuration:

Dropzone.options.portfolioForm = {
    // ... other config options
    autoProcessQueue: false,
    init: function() {
        var myDropzone = this;
        this.element.querySelector("button[type=submit]").addEventListener("click", function(e) {
            e.preventDefault();
            e.stopPropagation();
            myDropzone.processQueue();
        });
    }
}

The Challenge with Existing Files

You want to display the images already uploaded by a user when they edit the form again. You found the Dropzone Wiki FAQ which populates the dropzone-preview area with existing server-side files:

https://github.com/enyo/dropzone/wiki/FAQ#how-to-show-files-already-stored-on-server

However, this method doesn’t include the existing images in the queue for submission. This raises two key questions:

  1. Processing Existing Files: If these files aren’t in the queue, how can they be updated or removed on the server-side? Removing a file that wasn’t added to the queue seems complicated.

  2. Approach Choices: Should you add existing images back into the queue, or just send information about which files should be deleted?

Best Practices for Handling Existing Files

Adding Existing Images Back to the Queue

The simplest approach is to re-add existing images to the Dropzone queue using the addFile method. This ensures they are processed alongside new uploads.

// Assume this is your pre-existing image data
var existingImage = {
    name: "existing_image.jpg",
    size: 12345,
    type: "image/jpeg",
    // ... other properties
};

// Re-add to the queue
myDropzone.addFile(existingImage);

Sending Deletion Information Separately

An alternative is to maintain a list of existing files separately and send this alongside your form data. When a file is removed, add it to the deletion list.

// Maintain a list of existing files
var existingFiles = [];

// Add an event listener for 'removedfile'
myDropzone.on("removedfile", function(file) {
    // Add removed file to the deletion list
    existingFiles.push(file.name);
});

// When processing, send both new uploads and the deletion list
function processQueue() {
    var formData = new FormData(myDropzone.element);

    // Append deletion list data
    for (var i = 0; i < existingFiles.length; i++) {
        formData.append("deleted_files[]", existingFiles[i]);
    }

    // Process the queue normally
    myDropzone.processQueue();
}

Both approaches have their merits. Adding files back to the queue is simpler but may use more bandwidth for unchanged images.

Sending deletion information separately requires more server-side work but reduces bandwidth usage. This approach also allows you to handle deletions independently of Dropzone’s automatic queue processing.

For a clean, efficient solution, I recommend combining these approaches:

  1. Add existing files back into the Dropzone queue using the addFile method.
  2. Maintain a separate list of deleted files.
  3. When processing, send both new uploads and the deletion list separately.

This gives you the simplicity of Dropzone for handling existing files while retaining control over deletions. It’s compatible with your current setup and provides optimal performance.

Remember to update your server-side code to handle both new uploads and file deletions based on this combined approach.

Further Reading

For more information on optimizing image uploads in Laravel, check out our guide on Image Uploads in Laravel.

The Dropzone documentation provides detailed examples of handling existing files:

DropzoneJS Documentation

This covers additional methods like addFile and event listeners for file removal, which are essential for your use case.

Database Configuration JavaScript CLI

Our network