react-media-recorder icon indicating copy to clipboard operation
react-media-recorder copied to clipboard

send blob to server

Open arezooalipanah opened this issue 4 years ago • 6 comments

hi Thanks for creating this package Where do I access the blob itself? How can I send the blob as file to the server?

arezooalipanah avatar Sep 07 '20 20:09 arezooalipanah

const audioBlob = await fetch(mediaBlobUrl).then(r => r.blob());

and send it to server like this

            const audiofile = new File([audioBlob], "audiofile.webm", { type: "audio/webm" })

            console.log(audiofile);

            const formData = new FormData();

            formData.append("file", audiofile);

            const result = await axios.post(
                `<your server post end point>`,
                formData,
                {
                    crossDomain: true,
                }
            )

satyajitghana avatar Nov 27 '20 16:11 satyajitghana

const audioBlob = await fetch(mediaBlobUrl).then(r => r.blob());

Hey I tried to implement this part as follows but I can't get the blob what am I doing wrong please ? I am trying to call the getBlob function but I can't find a place where to call it properly

import React from "react"; import { ReactMediaRecorder } from "react-media-recorder";

export default function UserRecord() { const getBlob = async (mediaBlobUrl) => { const audioBlob = await fetch(mediaBlobUrl).then((r) => r.blob()); console.log(audioBlob); };

return ( <ReactMediaRecorder audio render={({ status, startRecording, stopRecording, mediaBlobUrl }) => (

{status}

<button onClick={startRecording}>Start Recording <button onClick={stopRecording}>Stop Recording
)} /> ); }

liadbelad avatar Dec 09 '20 13:12 liadbelad

@liadbelad I had it done by hooking onto the onStop event, where the complete blob is supplied. Supply the function pointer when creating the react hook, and in your onStop method you should have the URL and BLOB.

manzurola avatar Feb 08 '21 16:02 manzurola

Adding onto what @manzurola said, you can just do the following and that way you don't have to do fetch:

 <ReactMediaRecorder
onStop={(blobUrl, blob) => { console.log(blob); } }
... />

chuckthepiranha avatar Mar 10 '21 20:03 chuckthepiranha

I'm having problems to hook the onStop event, can somebody help me plesas?

@liadbelad I had it done by hooking onto the onStop event, where the complete blob is supplied. Supply the function pointer when creating the react hook, and in your onStop method you should have the URL and BLOB.

agusabreuc avatar May 06 '22 06:05 agusabreuc

This doesn't work when posting to server, i get the file as text and not file

blob:http://localhost:5173/4ba49844-5cb3-47dc-b309-b1c5ed104e00

wapmastaz avatar Mar 18 '24 01:03 wapmastaz