Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created May 5, 2019 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/15a25b9e011b70120b09db81628c5220 to your computer and use it in GitHub Desktop.
Save parzibyte/15a25b9e011b70120b09db81628c5220 to your computer and use it in GitHub Desktop.
// Cuando se detenga (haciendo click en el botón) se ejecuta esto
mediaRecorder.addEventListener("stop", () => {
// Detener el stream
stream.getTracks().forEach(track => track.stop());
// Detener la cuenta regresiva
detenerConteo();
// Convertir los fragmentos a un objeto binario
const blobAudio = new Blob(fragmentosDeAudio);
const formData = new FormData();
// Enviar el BinaryLargeObject con FormData
formData.append("audio", blobAudio);
const RUTA_SERVIDOR = "guardar.php";
$duracion.textContent = "Enviando audio...";
fetch(RUTA_SERVIDOR, {
method: "POST",
body: formData,
})
.then(respuestaRaw => respuestaRaw.text()) // Decodificar como texto
.then(respuestaComoTexto => {
// Aquí haz algo con la respuesta ;)
console.log("La respuesta: ", respuestaComoTexto);
// Abrir el archivo, es opcional y solo lo pongo como demostración
$duracion.innerHTML = `<strong>Audio subido correctamente.</strong>&nbsp; <a target="_blank" href="${respuestaComoTexto}">Abrir</a>`
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment