Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

277
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda