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

371
Visualizações
Javascript how to upload a mp3 file from a link

I'm wanting to get the contents of a mp3 file from a url get_mp3_file(mp3_file), then upload the contents of the mp3 I just downloaded, to another webserver and get the response.

var mp3_url = 'https://example.com/song.mp3';

function get_mp3_file(mp3_url) {
    const xhr = new XMLHttpRequest();
    xhr.open('GET', mp3_url, false);
    xhr.send();
    return xhr.responseText;
}

var fd = new FormData();
fd.append("file", get_mp3_file(mp3_url));

var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://mp3-to-wav.com/upload-file.php', false);
xhr.send(fd);
var wav_link = JSON.parse(xhr.responseText).link;
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

the key was the File class. here's more about it. https://w3c.github.io/FileAPI/#file-constructor

The solution for retrieving the contents of a file from one webserver, and then uploading it to another webserver:

var mp3_url = 'https://example.com/song.mp3';

var xhr = new XMLHttpRequest();
xhr.open('GET', mp3_url, false);
xhr.responseType = 'blob';

xhr.onload = function() {
    var xhr2 = new XMLHttpRequest();

    var file = new File([xhr.response], 'song.mp3', {type: 'audio/mp3'});
    var formData = new FormData();
    formData.append('file', file);
    

    xhr2.open('POST', "https://convert-mp3-to-wav.com", false);
    xhr2.send(formData);

}

xhr.send();
about 4 years ago · Santiago Gelvez 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