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

242
Views
Image compression in Flutter Web using JS returning null

I have a social networking PWA in flutter where I allow users to upload images and I am storing those images on Firebase storage. Now the issue is, currently, I am not able to find any proper compression method within Flutter. Hence, I decided to use JS for it, but unfortunately, that JS is returning the compressed file as null.

function compressAndDownloadImage(base64) {
var url = base64;

fetch(url)
    .then(res => res.blob())
    .then(blob => {
        var imageFile = blob;
        console.log('originalFile instanceof Blob', imageFile instanceof Blob); 
        console.log(`originalFile size ${imageFile.size / 1024 / 1024} MB`);

        var options = {
            maxSizeMB: 0.2,
            maxWidthOrHeight: 1920,
            useWebWorker: true
        }
        imageCompression(imageFile, options)
            .then(function (compressedFile) {
                console.log('compressedFile instanceof Blob', compressedFile instanceof Blob); 
                console.log(`compressedFile size ${compressedFile.size / 1024 / 1024} MB`); 
                console.log(compressedFile);
                saveAs(new Blob([compressedFile], { type: "image/jpeg" }), Math.floor(Date.now() / 1000) + '.jpeg');
                return compressedFile;
         
            })
            .catch(function (error) {
                console.log(error.message);
            });
    })

}

Please let me know what's wrong with the JS script that it is returning null.

Thanks in advance.

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!