react-native-ssl-pinning: FormData not being sent in Request
My goal is to send an image to my backend.
What I’m doing to send the request
const data = new FormData();
data.append('file', {
name: 'some_random_name.jpg',
type: 'image/jpeg',
path: getURI()
});
await fetchSSL('/api/files', {
method: 'PUT',
headers: {
'Accept': 'application/json',
'User-Agent': userAgent
},
disableAllSecurity: true, // for easier testing
pkPinning: false, // for easier testing
sslPinning: {
certs: [] // for easier testing
},
body: {
formData: data
}
})
the form data being passed, can be seen in the screenshot
I intercepted the request before it hit my servers and it appears the form data has not been appended (this looks different when not using this library):
The library itself also does not give me any notice about something going wrong. Of course, I get an error in the response from my server, but i would expected to get some kind of error.
I have tried to use the example from your readme. So the multi-part/form content type header has already been omitted. I also see the form Data being used when i added some logging statements to your native coe
I have seen in other issues that you recommended using base64, but when i have both path
and data
, the data seems to not have any effect, and only using data
caused an error somehow like (https://github.com/MaxToyberman/react-native-ssl-pinning/issues/38)
I would greatly appreciate your help, since your library seems to be the only way to provide ssl pinning while also having a feedback to the react native js code to show some nice alerts if something goes wrong. However, not being able to upload images makes this unusable, since this is a hard requirement for us.
Context: RN Version: 0.63.3 RN-SSL-Pinning Version: 1.5.4 OS: iOS (have not validated Android) Normal json body payloads work fine When ditching this library and using default react native fetch method, it also works fine
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 15 (3 by maintainers)
@Nageshwar1213 No sadly not. We have essentially put the effort to do ssl pinning on hold until this is issue is resolved…
@MaxToyberman One observation here was that whenever I am trying to send a file from iOS with path
/private/var/mobile/Containers/Data/Application/F30274B3-C753-46A1-BDAB-770E2FE837E5/tmp/react-native-image-crop-picker/B69FDAE9-556C-4192-BC2E-035DC48B7115.jpg
the image upload fails and the request header shows'content-length': 0
When the same image is sent from a different file pathfile:///var/mobile/Containers/Data/Application/F30274B3-C753-46A1-BDAB-770E2FE837E5/tmp/D20FB665-1359-42A7-9506-DF84EDD93C4B.jpg
the image uploads correctly.