Puedo guardar el archivo de imagen cargado en el servidor como:
$("#postImage").click(()=> { var canvas = cropper.getCroppedCanvas(); var width = canvas.width; if(canvas == null) { return alert("Could not upload the image. Make sure it is an image file."); } let image = new Image(); image.src = canvas.toDataURL(); image.id = "toBeUploaded"; canvas.toBlob((blob) => { var formData = new FormData(); formData.append("croppedImage", blob); $.ajax({ url: "/api/users/uploadImage", type: "POST", data: formData, processData: false, contentType: false, success: (uploadedImageURL, status, xhr) => { if(xhr.status == 200) { uploadedImageLink = uploadedImageURL; } else { alert("Unable to Upload the Image selected. Please try again!"); return; } } }) }) }) router.post("/uploadImage", upload.single("croppedImage"), async (req, res, next) => { if(!req.file){ console.log("No file uploaded with the ajax request."); return res.sendStatus(400); } var filePath = `/uploads/${req.file.filename}.png`; var tempPath = req.file.path; var targetPath = path.join(__dirname, `../../${filePath}`); fs.rename(tempPath, targetPath, async error => { if(error != null){ console.log(error) return res.sendStatus(400); } res.status(200).send(filePath); }) }) <input id="filePost" accept="image/*" type="file"/> <button id="postImage" type="button">OK</button>Para el archivo de imagen, tengo el paquete cropper js del usuario y utilicé la función toBlob() para llamar a la API uploadImage. Funciona bien.
<input id="fileAudio" accept="audio/*" type="file"/> <button id="postAudio" type="button">OK</button>Sin embargo, ahora quiero guardar archivos de audio de la misma manera. Pero de Internet descubrí que toblob es para los archivos de imagen. Intenté usar filereader() y muchas otras formas, pero no pude guardar el archivo de audio cargado en el lado del servidor.
¿Alguien puede sugerir cómo lograrlo?