Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

370
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!