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

459
Views
How do I restrict the file size if my reference is the Base64 version of the file?

If a user uploads a file (e.g. an mp3), using a standard <input type="file"/>, I will store their file in the DB as a Base64 string.

However, I realised that the size of the Base64 string will be bigger than the size of the file.

For example, if the file the user uploads is 3984547 bytes I then convert it into a Base64 string and then calculate the size of that string with:

function base64bytes(fileAsBase64) {
  return (new TextEncoder().encode(fileAsBase64)).length
}

and the value returned is 5312755 bytes.

So if the user uploads a ~3.9Mb file, the Base64 string I will store in the DB will be ~5.3Mb.

My problem is that I want to only allow Base64 strings of up to 100Mb.

But I don't know how to let the user know about it.

If I tell the user that I only allow files of up to 100Mb that will be misleading. They might upload a file that is 98Mb on their machine but my Base64 string will be probably bigger than 100Mb so I will reject their file and confuse them.

According to this answer the Base64 version of an image is always ~137% bigger than the original image file. But does this ratio only stand for images ? My files could be of any type.

Is this ratio safe enough to use on any type of file or would you suggest some other solution to my problem?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The base64 version of a file is at least 33% larger than the original file. The increase depends on the file size, the smaller the file, the larger the increase.

Allowing an upload file size of 75MB would lead to a base64 encoded files of around 99.75MB.

about 4 years ago · Juan Pablo Isaza 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!