Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thee uploaded image is not considering the transformed file #2238

Open
digounet opened this issue Jun 18, 2023 · 0 comments
Open

Thee uploaded image is not considering the transformed file #2238

digounet opened this issue Jun 18, 2023 · 0 comments

Comments

@digounet
Copy link

digounet commented Jun 18, 2023

Describe the bug
I'm using the lib compressor to compress the file on client side before upload it to an azure container. he copress occurr with success but the uploaded version is always the original version.

my code:

var myDropzone = new Dropzone(id, {
            url: "/Image/Upload",
            dictInvalidFileType: "Apenas arquivos jpeg ou jpg são suportados",
            dictUploadCanceled: "Upload cancelado",
            dictFileTooBig: "Arquivo muito grande ({{filesize}}MiB). Máx. permitido: {{maxFilesize}}MiB.",
            dictInvalidFileType: "Tipo de arquivo não permitido.",
            autoProcessQueue: true,
            autoQueue: true,
            method: "PUT",
            headers: { "x-ms-blob-type": "BlockBlob", "x-ms-version": "2017-11-09" },
            clickable: true,
            maxFilesize: MAX_FILE_SIZE,
            createImageThumbnails: false,
            acceptedFiles: ".jpeg,.jpg",
            previewTemplate: previewTemplate,
            previewsContainer: id + " .dropzone-items",
            transformFile: function (file, done) {
                new Compressor(file, {
                    quality: 0.6,
                    success(compressedFIle) {
                        done(compressedFIle);
                    },
                    error(err) {

                        done(file);
                    }
                });
            },
            sending: (file, xhr) => {
                // To send file without wrappintng it to multipart/form-data,
                // Azure won’t unwrap it
                const _send = xhr.send;
                xhr.send = () => { _send.call(xhr, file) };
            },
            renameFile: function (file) {
                return `${Date.now()}___${userid}___${projectid}___${file.name}`;
            },
            init: function () {
                const dz = this

                dz.on("processing", (file) => {
                    dz.options.headers["Content-Type"] = file.type;
                })
            },
            accept: function (file, done) {
                // code to check if file already exists
            }
        });

        myDropzone.on("processing", function (file) {
            // I need to do an async call here, to get the URL...
            setSasUrl(file, myDropzone); 
        });

        // Adicione um ouvinte para o evento `addedfile`
        myDropzone.on("addedfile", function (file) {
            controlFileAdded(file, dropzone);
            
        });

        //uploadprogress
        myDropzone.on('uploadprogress', (file, progress, bytesSent) => {
            const progressBar = file.previewElement.querySelector(".progress-bar");
            progressBar.style.width = progress + "%";
        });

        //sending
        myDropzone.on("sending", function (file) {
            // Show the total progress bar when upload starts
            const progressBar = file.previewElement.querySelector(".progress-bar");
            progressBar.style.opacity = "1";
        });

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

        //reset
        myDropzone.on("reset", function () {
            sentFiles = 0;
            addedFiles = 0;
            errorFiles = 0;
            setTotalProgress();
        });

        myDropzone.on("success", function (file) {
            sentFiles += 1;
            setTotalProgress();
        });
    };

    function setSasUrl(file, myDropzone) {
       //code o get the upated SAS URL.
    }

    function controlFileAdded(file, dropzone) {
       //code to adjust proggress bars
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant