benjreinhart / react-native-aws3

Pure JavaScript React Native library for uploading to AWS S3
MIT License
399 stars 151 forks source link

Cannot upload image on Android device #48

Open klammm opened 7 years ago

klammm commented 7 years ago

Thank you for this library btw. It's been incredibly helpful.

Anyways, I'm having trouble uploading images to S3 when I am simulating on Android. On iOS, I have no troubles at all.

Note: I am using React-Native-Camera I am currently using:

{
"react-native": "0.43.0",
"react-native-camera": "git+https://github.com/lwansbrough/react-native-camera.git",
"react-native-aws3": "0.0.8",
}

Here's my code:

    this.camera.capture()
      .then((data) => {
        this.setState({ path: data.path })
        const file = {
          uri: data.path,
          name: `${uuid.v1()}.jpg`,
          type: 'image/jpeg',
        };

        const options = {
          keyPrefix: 'photos/',
          bucket: 'accountabilibuddy-1',
          region: 'us-west-1',
          accessKey: AWSAccessKeyId,
          secretKey: AWSSecretKey,
          successActionStatus: 201
        };

        RNS3.put(file, options).then(response => {
          if (response.status !== 201) {
            throw new Error('Failed to upload image to S3', response);
          }
          this.props.pictureTaken(response.body.postResponse.location) // reduxAction here(don't mind)
        }).catch(err => console.error('Camera error not uploaded: ', err))
      })
      .catch(err => console.error(err));
  }

For the inner catch, I am getting the following error:

screenshot_20170619-172817

For the outer catch, I am getting the following error:

screenshot_20170619-173258

Has this library worked for others on Android?

truongnmt commented 7 years ago

yes I'm struggling with this error as well :(

chuson1996 commented 7 years ago

@smokymcbear @truongnmt are you still having this error?

MrHubble commented 6 years ago

@smokymcbear @truongnmt @chuson1996 would you be able to provide your solution for this? Thanks.

klammm commented 6 years ago

@chuson1996 @MrHubble : I'm not getting an error for this anymore. I was able to solve it by providing the correct AWSSecretKey and AWSAccessKeyId within my .env file as reflected within my bucket accountabilibuddy-1. Basically, I was providing the wrong keys. #feelsbad

Here's the example code where I got it to work: https://github.com/smokymcbear/Accountabili-buddy/blob/master/src/containers/Camera.js

Hope this helps 😁

chongdog83 commented 6 years ago

I'm also having this problem, the library was super easy to setup and worked immediately.... on iOS. Then when I tested on Andriod its throwing errors.

In my specific case, I am using the Expo Image Picker (ImagePicker.launchImageLibraryAsync) then feeding the file that was picked into React Native ImageEditor to resize it.

I suspect the issue is centered around the file location?

When I console.log the file location on Andriod: file:///data/user/0/host.exp.exponent/cache/ReactNative_cropped_image_777159874.jpg

When I console.log the file location on iOS: rct-image-store://0

chongdog83 commented 6 years ago

I dont know why but its now working. Fortunately, I was committing to git as progress was being made and was able to go back in time and diffmerge my code... there wasn't any changes... it just started working.

I'm going to blame this on me forgetting to restart the packager after I started using the library. Perhaps the reason I worked in iOS was because I fired up my test iPhone after I installed the library? I don't know. But if anyone else finds this, restart Expo or your RN packager and maybe you wont have this problem and waste 2 hours.

Thanks to those who made this library.... even with me being retarded this was still easier than dealing with it from scratch!