1

My Rails API seems to be working fine, when I POST an image to S3 via postman. However, when I use React Native image picker, I don't think I'm sending the parameters in the correct way.

I am currently sending the image uri as the image parameter (the uri of the image picked from the image picker). Should I be sending something else as the image parameter?

Here is a part of my async function to make a POST request to the Visions table:

    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
              }
            })
        });

In this case, this.state.uploadfile is the response.uri that I am getting when I pick an image from Image picker, which is formatted like:

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

I am getting a 500 error:

ActionView::Template::Error (to_model delegated to attachment, but attachment is nil):

Ozge Cokyasar
  • 301
  • 1
  • 4
  • 16

0 Answers0