infinitered / apisauce

Axios + standardized errors + request/response transforms.
MIT License
2.79k stars 185 forks source link

Upload image not working on 3.0.1 #317

Open AbhijitKurane opened 1 year ago

AbhijitKurane commented 1 year ago

Below is the code,


        const form = new FormData()

        form.append('image', {
          name: imageFileName,
          type: imageType,// image/jpeg
          uri: Platform.OS === 'ios' ? imageFilePath.replace('file://', '') : imageFilePath,
        })

        const result = await userInfo.updateUserImage(form)

This fails to work on version 3.0.1 with http error code 400 bad request but the same works on version 2.1.6. I did checked for logs in addAsyncRequestTransform method. For both version 2.1.6 as well as 3.0.1 the request json formed is same but the image gets uploaded successfully on version 2.1.6 and fails on 3.0.1 with http error code 400 bad request.

wesleyvandevoorde commented 10 months ago

I have the same issue

pnthach95 commented 10 months ago

Have you tried adding 'Content-Type': 'multipart/form-data' to header? It has 'Content-Type': 'application/json' by default even if you use FormData

hassan-viabletree commented 7 months ago

Have you tried adding 'Content-Type': 'multipart/form-data' to header? It has 'Content-Type': 'application/json' by default even if you use FormData

This worked.