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

518
Visualizações
Convert to base64 from response.body which is in readablestream format

I have a http request in javascript that returns content of a file in the response. The response.body is in readablestream format. I need to get the file content in base64 format and upload in a different location. Can I know what is the best approach to convert the content to base64 string?

var url="httpurl";
var dataContent= await fetch(url);

var textContent= await dataContent.blob(); 

Next line is to make https call to upload a file with content in base64 string format.

I would like to know how the datacontent can be converted to base64 string.

dataContent is as in below image:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This answer has more info on how to get the response from a ReadableStream. Here's the main part with the base64 conversion included. The base64encode function is based on this

function base64encode(str: string): string {
  return btoa(unescape(encodeURIComponent(str)));
}

fetch('https://jsonplaceholder.typicode.com/posts/1')
  .then(function(response) {
    return response.text();
  }).then(function(data) {
    const base64encodedData = base64encode(data);
    console.log(data); // this will be a string
  });
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