Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
How can I programmatically upload an image using Dropzone

What is the correct way to upload a file programmatically using Dropzone? I have been using the code below to do it but it has not been working. My actual code opens a modal and allows the user to take an image and add the image to Dropzone on the main page.

Problems that I am having:

  1. My files keep on getting duplicated when I use the modal form to add the file to the dropzone on the main page. (I think my event handliers are being duplicated every time I open the modal but my short fixes haven't been working)

  2. The file added programmatically is not uploaded to the server. Request.Files does not contain the uploaded file. (All manually uploaded files are in Request.Files)

var myDropzone = null;
    Dropzone.options.uploadForm = {
        paramName: "file", // The name that will be used to transfer the file
        maxFilesize: 10, // MB
        uploadMultiple: true,
        maxFiles: 4,
        clickable: true,
        autoProcessQueue: false,
        parallelUploads: 10,
        addRemoveLinks: true,
        acceptedFiles: "image/*",
        accept: function (file, done) {
            done();
        },
        init: function () {
            myDropzone = this;

        $(document).off('click').on("click", "#uploadCapturePhotoToDropZone", function(e) 
        {
                e.preventDefault();

                var number = 1 + Math.floor(Math.random() * 6);
                var fileBase64 = $("#capturePhotoID").val();
                var mockFile = {
                    name: "capturePhoto.png",
                    size: 12345,
                    type: 'image/png',
                    status: Dropzone.ADDED,
                    url: fileBase64,
                    serverID: number,
                    accepted: true 
                };

                myDropzone.emit("addedfile", mockFile);
                myDropzone.createThumbnailFromUrl(mockFile, fileBase64);
                myDropzone.files.push(mockFile);

                $(".dz-progress").show();
                $("#LoaderIconGov").show();
                myDropzone.processQueue();
            });

My modal form has the following partial code to send the base64 image to the main form and call the action to upload the image

$(document).on("click", "#addImageToMainPage", function (e) {
    e.preventDefault();
    $("#capturePhotoID").val(imageData);
    $("#uploadCapturePhotoToDropZone").click();
    $('#myModal0').modal('toggle');
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!