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

184
Views
Trying to Create a File from Blob but the Output file has Invalid Size

I am creating a canvas to rotate an image and creating a blob. But I need it as a file to upload it to server.

return new Promise((resolve, reject) => {
        canvas.toBlob(blob => {
            // returning an error
            if (!blob) {
                reject(new Error('Canvas is empty'));
                return;
            }
            // blob.name = fileName;
            // creating a Object URL representing the Blob object given
            const rotatedImageUrl = window.URL.createObjectURL(blob);
            resolve(rotatedImageUrl);
        }, 'image/jpeg');
    });

I am trying to create a file from the blob . I'm able to create it by using this snippet.

const rotatedFile = new File([img], originalFile.name, {
        type: originalFile.type,
    });

But the problem is generated file size is only 58 byte.

lastModified: 1644577677380
lastModifiedDate: Fri Feb 11 2022 17:07:57 GMT+0600 (Bangladesh Standard Time) {}
name: "IMG_4792.JPG"
size: 58
type: "image/jpeg"
webkitRelativePath: ""

I think the image is corrupted somehow. Initially I thought canvas is somehow corrupting my image but I have also tried to create a file from an uploaded file converted to blob. That also gave me the same output. File size is not correct.

const file = e.target.files[0];
const blobUrl = URL.createObjectURL(file);
const generatedFile = new File([blobUrl], 'untitled', {
            type: file.type,
        });

Is there any solution? How can I properly create the file from the blob?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Why are you using the createObjectURL ?

You should resolve the blob directly resolve(blob); and then the file will correctly represent the image, instead of representing the objectURL.


What you are seeing is the length of the generated url. Something like "blob:https://........'

over 4 years ago · Santiago Trujillo Report
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!