0

I am creating react-native app which allows me to take a picture using camera and upload to AWS S3.

I am able to click the picture and save image to my iPhone camera roll. But, when I try to upload the image, I get error No suitable URL request handler found for assets-library://asset as shown below: iOS image upload error Here is the code snippet:

import Camera  from 'react-native-camera';    
import {RNS3} from "react-native-aws3";

    class NCamera extends React.Component {
        takePicture() {
            this.camera.capture()
                .then((data) => {
                    const file = { uri: data.path, name: 'image.png', type: 'image/png',}
                    const options = {
                        keyPrefix: "images/",
                        bucket: "my-bucket-name",
                        region: "us-east-1",
                        accessKey: "key",
                        secretKey: "secret-key",
                        successActionStatus: 201
                    }
                    RNS3.put(file, options)
                        .then(response => {
                            if (response.status != 201 )
                                console.log('Error uploading file to S3');
                            else
                                console.log(response.body);
                    })
                        .catch (error => console.log(`Error uploading: ${error}`));
                })
                .catch(err => console.log(err));
        }
        render() {
            return (
                <Camera
                    ref={(cam) => {
                        this.camera = cam;
                    }}
                    style={styles.preview}
                    aspect={Camera.constants.Aspect.fill}>
                    <Text style={styles.capture} onPress={this.takePicture.bind(this)}>[CAPTURE]</Text>
                </Camera>
            );
        }
    }

Solution
I added libRCTCameraRoll.a which resolved the issue.

Here are the steps:
1. Open RCTCameraRoll.xcodeproj in xcode. The file can be found under node_modules/react-native/Libraries/CameraRoll
2. Under Build Phases, add libRCTCameraRoll.a(screenshot below).

enter image description here

RC_02
  • 3,146
  • 1
  • 18
  • 20

1 Answers1

1

If this is on IOS, I think you need to link libRCTCamera.a in XCode so that the file url can be resolved properly. See this medium article for more details on that.

Ian Mundy
  • 376
  • 1
  • 8
  • Adding `libRCTCameraRoll.a` fixed the issue. I updated my post with the solution. Thanks for the link. It helped me resolve issue. – RC_02 Dec 25 '17 at 21:03