Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

457
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda