Uso dropzone.js y bibliotecas de compresión de imágenes. Pero tengo problemas para descargar el blob. Algún consejo de cómo puedo hacerlo. Eso es a continuación es mi código
// "myDropzone" is the camelized version of the HTML element's ID Dropzone.options.myDropzone = { url:" ", transformFile: function(file, done) { const imageCompressor = new ImageCompressor(); imageCompressor.compress(file, { // I assume the output image won't have the meta data anymore checkOrientation: true, // Limit output image width & height // For controllable file size & avoid blank output image // https://github.com/xkeshi/image-compressor#maxwidth maxWidth: 8192, maxHeight: 8192, // 0.8 is the default and already good enough quality: 0.6, // Convert ALL PNG images to JPEG convertSize: 0, }) .then((result) => { // Handle the compressed image file. done(result) console.log(result); }) .catch((err) => { // Handle the error throw err }) } };intento crear un enlace de descarga y descargar el "resultado", pero obtengo un archivo corrupto
Encontré la solución por mí mismo. Hice ObjectURL del blob y luego creo un elemento "a"
const url = window.URL.createObjectURL(result); const a = document.createElement('a'); a.style.display = 'none'; a.href = url; // the filename you want a.download = result.name; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url);