Adi Dasler
Adi Dasler

Reputation: 528

react-media-recorder. Send audio to the server (backend) or get blob from mediaBlobUrl

Needed to send mediaBlobUrl to the server:

const {
    mediaBlobUrl
  } = useReactMediaRecorder({
    audio: true,
  });

Upvotes: 2

Views: 5697

Answers (1)

Adi Dasler
Adi Dasler

Reputation: 528

Thats how you can get blob from mediaBlobUrl or change mediaBlobUrl to blob:

const handleSave = async () => {
    const audioBlob = await fetch(mediaBlobUrl).then((r) => r.blob());
    const audioFile = new File([audioBlob], 'voice.wav', { type: 'audio/wav' });
    const formData = new FormData(); // preparing to send to the server

    formData.append('file', audioFile);  // preparing to send to the server

    onSaveAudio(formData); // sending to the server
  };

Upvotes: 3

Related Questions