How to upload Audio or generic filetype

for some reason posting an audio file as multipart/form-data doesn’t work the payload shows up as [object object]. below is a snippet where i get a signed url from google storage then post the form data to it, everything works but the request body is just [object object] instead of form data.

const data = new FormData()

    const meta = {
      uri, // "file://dsfsdfd/sfsfsd.caf"
      name: 'something.caf',
      type: 'audio/caf',
    }
    console.log(meta)
    data.append('file', meta)
    console.log('data pre send', data)
    try {
      const response = await fetch(`${signed_url}`, {
        body: data,
        method: 'PUT',
        headers: {
          'Content-Type': 'multipart/form-data',
        },
      })
      console.log('upload', response) // success
    } catch (e) {
      console.log('no upload', response)
    }
  }

  postImageToServer = (ticketId, params) => {
    return axios
      .post(`/tickets/${ticketId}/imageUpload`, params)
      .then(response => response.data, () => (this.state = 'error'))
  }
}

it works, there is a bug in your code somewhere, see this example examples/with-formdata-image-upload at master · expo/examples · GitHub

1 Like

I’m not sure what I’m doing wrong everything looks right excpet the request body being [object object]
49 PM

perhaps turn off chrome debugging

1 Like

I have tried, I use a CORs pluging when it is on, and get a 200 response (not a resource policy warning)

I tried setting up a snack but it doesn’t seem to work
https://snack.expo.io/HykAAergf

does https://expo.io/@community/image-upload-example work for you?

Hey yes it works,
I guess it’s just images.
Tried modifying it for audio https://snack.expo.io/S1QyIZSxf

the example you shared doesn’t do anything - what is sound.caf? there is no such file. further, the backend that you’re using (the one from the example repo) is specifically intended for images: https://github.com/expo/examples/blob/master/with-formdata-image-upload/backend/index.js#L25-L37

sound.caf is an audio file created with expo. it can be seen in the left under the files of the snack… Let’s close off this issue, I’ll explore some alternative solutions…

You were right the remote debugging tools with the CORs plugin were malforming the request. Thank you for the help.