Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

456
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda