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

383
Visualizações
How to get base64 image files with filename length over 100 characters using javascript, ReactJS

I'm trying to get the base64 (FileReader) image data after the file list is uploaded But files whose names are longer than 100 characters cannot be retrieved. Is there a way for me to solve this problem, I don't want to change the filename because the number of it is too much. You can see the attached photo.

enter image description here

File name:

  1. Kyle Larson 77 Nascar Racing Sports Classic Tee, Men's T-Shirt, Hoodie - Katycollection 1.jpg => work
  2. Kyle Larson Drilling for Oil Nascar Racing Sports Classic Tee, Men's T-Shirt, Hoodie - Katycollection 1.jpg => Not working

Here is my code

function getBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result);
    reader.onerror = error => reject(error);
 });
}
async onBeforeUpload(file) {
    this.setState({ loadingUpload: true })
    var path = file.webkitRelativePath;
    let pathArray = path.split('/');
    let fName;
    if (pathArray.length == 2) {
        fName = file.name.replace(/\.[^/.]+$/, "");
    } else {
        fName = pathArray.slice(-2)[0];
    }
    //console.log(file.name.length,": ", file.name)
    let data = await getBase64(file);
    const objectImg = {
        folderName: fName,
        description: "<p>" + fName + "</p>\n",
        images: {
            data: data,
        }
     }
     this.setState({ imageList: [...this.state.imageList, objectImg] })
  }

Update:

I use ant design's Upload component and upload directory

<Upload
    beforeUpload={(file) => this.onBeforeUpload(file)}
    directory
    showUploadList={false}
    accept="image/*"
    customRequest={() => {
        return false;
    }}
>
    <Button className="table-button" type="primary">Upload</Button>
</Upload>

Thanks in advance

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