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:
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).