我正在创建 react-native 应用程序,它允许我使用相机拍照并上传到 AWS S3。
我可以单击图片并将图像保存到我的 iPhone 相机胶卷。但是,当我尝试上传图片时,出现No suitable URL request handler found for assets-library://asset
如下所示的错误:
这是代码片段:
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>
);
}
}
我添加的解决方案libRCTCameraRoll.a
解决了这个问题。
以下是步骤: 1.在 xcode 中
打开。RCTCameraRoll.xcodeproj
该文件可以在node_modules/react-native/Libraries/CameraRoll
2 下找到。在 Build Phases 下,添加libRCTCameraRoll.a
(下面的屏幕截图)。