Search code examples
reactjsamazon-web-servicesreact-nativeamazon-s3aws-amplify

React Native + Amplify S3 Example


I'm looking for a thorough example of how to return the file name after successfully sending it to S3.

Currently I have something like:

uploadImageAsync = async (pickerResult) => {
    try {
      this.setState({
        uploading: true,
      })

      if (!pickerResult.cancelled) {
        const response = await fetch(pickerResult.uri);
        const blob = await response.blob();
        Storage.put(fileName, blob)
          .then(result => console.log(result))
          .catch(err => console.log(err))
      }
    } finally {
      this.setState({
        uploading: false,
      })
    }
  }

My return result is the filename that I created. I'd like to return the S3 filename after it is created. Is this possible?


Solution

  • You could perform a get() call for the image to get a signed url.

    Storage.put('profile-picture.jpeg', blob)
      .then(result => {
        Storage.get('profile-picture.jpeg')
          .then(result => {
            console.log(result);                    
          })
          .catch(err => {
            console.error(err);
          });
      })
      .catch(err => {
        console.error(err);
      });