React-Native Camera错误 - 找不到资产库的合适的URL请求处理程序

问题描述 投票:0回答:1

我正在创建react-native app,它允许我使用相机拍照并上传到AWS S3。

我可以点击图片并将图像保存到我的iPhone相机胶卷。但是,当我尝试上传图片时,我得到错误No suitable URL request handler found for assets-library://asset,如下所示:iOS image upload error这是代码片段:

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(下面的屏幕截图)。

enter image description here

react-native amazon-s3 react-native-camera
1个回答
1
投票

如果这是在IOS上,我认为您需要在XCode中链接libRCTCamera.a,以便可以正确解析文件URL。有关详细信息,请参阅this medium article

© www.soinside.com 2019 - 2024. All rights reserved.