Storing recorded sound clip on server using PHP in React Native

202 Views Asked by At

I am recording short audio clips and want to save them on a server using PHP, i.e. I have a recording object which creates .caf file, (ideally I want to convert it to MP3 and save it but that's a separate issue). but I want to save that file on a server using PHP. The code below is the code I use for recording audio.

const recording = new Audio.Recording();
await recording.prepareToRecordAsync(Audio.RECORDING_OPTIONS_PRESET_HIGH_QUALITY);
recording.setOnRecordingStatusUpdate(updateScreenForRecordingStatus);
await recording.startAsync();
1

There are 1 best solutions below

0
On

I actually figured it out, just posting for someone else who is experiencing similar situation. Posting recording object is pretty simple, it's just like posting an image using form date

formData.append('audio', { uri: recordedAudio.getURI(), name: "abc.caf", type:"audio/x-caf" });

and on PHP side

move_uploaded_file($_FILES['audio']['tmp_name'], './uploads/sounds/' . $_FILES['audio']['name']);