在 Postman 上将图像上传到 S3 有效,但当我使用 React Native Image Picker 时它不起作用

Uploading image to S3 on Postman works but it doesn't work when I use React Native Image Picker

提问人:Ozge Cokyasar 提问时间:3/27/2019 更新时间:3/23/2022 访问量:496

问:

当我通过 postman 将图像发布到 S3 时,我的 Rails API 似乎工作正常。 但是,当我使用 React Native 图像选择器时,我认为我没有以正确的方式发送参数。

我目前正在发送图像 uri 作为图像参数(从图像选取器中选取的图像的 uri)。我应该发送其他东西作为图像参数吗?

这是我的异步函数的一部分,用于向 Visions 表发出 POST 请求:

    let access_token = this.state.accessToken
    try {
        let response = await fetch('https://prana-app.herokuapp.com/v1/visions/', {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'X-User-Email': this.state.email,
                'X-User-Token': this.state.accessToken
            },
            body: JSON.stringify({
              vision: {
                description: 'YOYOYOYOYO',
                image: this.state.uploadFile
              }
            })
        });

在这种情况下,this.state.uploadfile 是我从图像选择器中选择图像时得到的,其格式如下:response.uri

file:///Users/ozgecokyasar/Library/Developer/CoreSimulator/Devices/EDD6C498-DACD-433E-B96D-3A30BAE7BA6D/data/Containers/Data/Application/B549F09A-EB40-4D9A-B8A8-B003362BE49D/Library/Caches/ExponentExperienceData/%2540anonymous%252Fmanifestation-react-3ac1cbe2-549f-49e7-8506-ef29638d1643/ImagePicker/28EAA390-F814-4A80-A188-8592B642BEFA.jpg

我收到 500 错误:

ActionView::Template::Error(to_model委托给附件,但附件为零):

react-native amazon-s3 图像上传 rails-activestorage react-native-image-picker

答: 暂无答案