title: how to send react-native-audio-record recorded audio file to server?
body: <p>I need to be record audio and upload audio to server and for the record audio i am using &quot;<strong>react-native-audio-record</strong>&quot; react native package.</p>
  <p>When i am using <code>file_get_contents($request-&gt;file('inputFile'))</code> all time <code>file_get_contents returning 500 internal server error</code> to me in <strong>Laravel</strong>.</p>
  <p>I tried <strong>form-data</strong>, <strong>blob object</strong>.</p>
  <p>Here is my React Native code and everything what i used to solve this:</p>
  <pre><code>onStartRecord = async () =&gt; {
      this.setState({ isPlaying: false })
      let dirs = RNFetchBlob.fs.dirs
      if (Platform.OS === 'android') {
        try {
          const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
            {
              title: 'Permissions for write access',
              message: 'Give permission to your storage to write a file',
              buttonPositive: 'ok',
            },
          );
          if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            console.log('You can use the storage');
          } else {
            console.log('permission denied');
            return;
          }
        } catch (err) {
          console.warn(err);
          return;
        }
      }
      if (Platform.OS === 'android') {
        try {
          const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
            {
              title: 'Permissions for write access',
              message: 'Give permission to your storage to write a file',
              buttonPositive: 'ok',
            },
          );
          if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            console.log('You can use the camera');
          } else {
            console.log('permission denied');
            return;
          }
        } catch (err) {
          console.warn(err);
          return;
        }
      }
      const path = Platform.select({
        ios: 'hello.m4a',
        //android: dirs.DocumentDir+'/hello.aac',
        android: 'sdcard/hello.mp3',
      });
      const audioSet: AudioSet = {
        // AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
        // AudioSourceAndroid: AudioSourceAndroidType.MIC,
        // AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high,
        // AVNumberOfChannelsKeyIOS: 2,
        // AVFormatIDKeyIOS: AVEncodingOption.aac,
      };
      //console.log('audioSet', audioSet);
      const uri = await this.audioRecorderPlayer.startRecorder(path);
      console.log(&quot;URI =&gt; &quot;,uri);
  
  
      // RNFS.readFile(uri, 'base64')
      // .then(res =&gt;{
      //   console.log(res);
      // });
      // RNFetchBlob.fs.writeFile(path, base64Str, 'base64');
      // RNFetchBlob.android.actionViewIntent(path, 'application/aac');
  
      this.audioRecorderPlayer.addRecordBackListener((e: any) =&gt; {
        //console.log(&quot;E ====&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;,e);
        this.setState({
          recordSecs: e.current_position,
          recordTime: this.audioRecorderPlayer.mmssss(
            Math.floor(e.current_position),
          ),
        });
      });
      //alert(`uri: ${uri}`);
      // var body = new FormData();
      // //console.log(&quot;BODY&quot;,abc);
      // body.append('file', uri);
      //
      // console.log(&quot;+++++++=========body=========++++++&quot;,body);
  
      var body = new FormData();
      //console.log(&quot;BODY&quot;,abc);
      body.append('inputFile', {
         name: 'sound.mp4',
         type: 'audio/mp3',
         uri: uri
      });
      console.log(&quot;+++++++=========body=========++++++&quot;,body);
      // console.log(&quot;BODY&quot;,body);
      // RNFS.readFile(uri, &quot;base64&quot;).then(data =&gt; {
      //   // binary data
      //   console.log(&quot;+++++++=========URI=========++++++&quot;,data);
      // });
  
  
  
  
  
        // const formData = [];
        // formData.push({
        //   name: &quot;sound&quot;,
        //   filename: `sound.mp4`,
        //   data: RNFetchBlob.wrap(uri)
        // });
  
      const blob = await (await fetch(uri)).blob();
      // const file = new File(this.state.recordTime, `me-at-thevoice${1}.mp3`, {
      //     type: blob.type,
      //     lastModified: Date.now()
      // });
      // console.log(&quot;Bolb data file&quot;,file);
  
      var bodyData = new FormData();
      //console.log(&quot;BODY&quot;,abc);
      bodyData.append('inputFile', { blob });
      //
      // console.log(&quot;RNFetchBlob blob&quot;,blob);
      // await new Promise(resolve =&gt; {
      //  var reader = new FileReader();
      //  reader.readAsDataURL(blob);
      //  reader.onloadend = () =&gt; {
      //      var base64data = reader.result;
      //     console.log(&quot;reader&quot;,reader);
      //     console.log(&quot;base64data =---&gt;&gt;&gt;&quot;,base64data);
      //      // let pth = path
      //      // RNFetchBlob.fs.writeFile(pth, reader.result.substr(base64data.indexOf(',')+1), 'base64').then((res) =&gt; {
      //     //   console.log(&quot;RNFetchBlob res&quot;,res);
      //      //  blob.close()
      //      //  resolve();
      //      // });
      //
          this.props.setLoader(true);
          this.props.uploadAudio(bodyData).then(result =&gt; {
            console.log(&quot;this.props.audioRecordingResponse |||||=====|||||&quot;,this.props.audioRecordingResponse);
            if (this.props.audioRecordingResponse.success) {
               this.handler('success','Success',this.props.audioRecordingResponse.message);
               // this.refs[&quot;sign&quot;].resetImage();
               // this.setState({
               //   signatures: [],
               //   isDragged: false,
               //   signatureCount: 0
               // })
               //this.props.navigation.navigate('AudioRecording',{templateId:templateId, documentId: documentId});
  
            } else {
              this.props.setLoader(false);
              this.handler('error','Error',this.props.audioRecordingResponse.message);
            }
          })
  
      //  }
      // })
  
    };
  </code></pre>
  <p>Please let me know if anyone having solution for the same.</p>