Quiero obtener el contenido de un archivo mp3 de una url get_mp3_file(mp3_file) , luego cargar el contenido del mp3 que acabo de descargar, a otro servidor web y obtener la respuesta.
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;la clave era la clase Archivo. aquí hay más al respecto. https://w3c.github.io/FileAPI/#file-constructor
La solución para recuperar el contenido de un archivo de un servidor web y luego cargarlo en otro servidor web:
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();