Jordan Daniels
Jordan Daniels

Reputation: 5304

React-Native send recorded audio to AWS S3

I am trying to make an instant chat with audio recordings in React-Native. I am having issues sending the recorded audio to S3.

I am using React-Native-Audio to record sound input, React-Native-Sound to play the recorded audio, and React-Native-aws3 to send files to AWS.

I am able to get the local recorded audio to play. Also, I can send pictures to S3. However, when I try to send the audio to AWS S3, and play the audio from the url given from S3, the audio doesn't work. S3 shows the file as 0 bytes.

Here is my code:

  const file = {
    audioPath, // `${AudioUtils.DocumentDirectoryPath}/test.aac`
    name: `${this.props.local.currentUserId}${moment
      .utc()
      .format("YYYY-MM-DD-HH-mm-ss")}.aac`,
    type: `audio/aac`
  };
  const options = {
    keyPrefix: ****,
    bucket: ****,
    region: ****,
    accessKey: ****,
    secretKey: ****
  };

  RNS3.put(file, options)
    .progress(event => {
      console.log(`percent: ${event.percent}`);
    })
    .then(response => {
      console.log(response, "response from rns3 audio");
      if (response.status !== 201) {
        console.error(response.body);
        return;
      }
      // ... handling the response
    })

I believe that the issue is that the actual audio recording is not being fetched.

Upvotes: 2

Views: 2229

Answers (1)

Jordan Daniels
Jordan Daniels

Reputation: 5304

Really silly syntax mistake.

const file = {
  uri: audioPath,
  name: `${this.props.local.currentUserId}${moment
         .utc()
         .format("YYYY-MM-DD-HH-mm-ss")}.aac`,
  type: `audio`
};

Just needed to add the uri property.

It's working now!

For those that want to see an example: https://medium.com/@decentpianist/react-native-chat-with-image-and-audio-c09054ca2204

Upvotes: 2

Related Questions