.attach didn't upload file
See original GitHub issueWe try to use superagent to upload file to our server by following this guide, https://visionmedia.github.io/superagent/#multipart-requests, on React Native project
here is our implementation code
superagent.post(full_url)
.field('type', 'image_type')
.attach('file', file.uri, {contentType: 'image/png'})
.then(response => {
console.log(`response ${JSON.stringify(response.body)}`)
callback(response.body)
})
.catch(error => {
console.log(`error body json stringify ${JSON.stringify(error)}`)
errorCallback(error)
})
file.uri
here is image that we got from react-native-camera
the field type
was received by server, but the file
was not there
response from server is, more or less
{
"status": false,
"data": "Required request part 'file' is not present"
}
we try to change the attach
parameter to
.attach('file', file.base64, {contentType: 'image/png'})
and
.attach('file', RNFetchBlob.wrap(file.uri), {contentType: 'image/png'})
and also
.attach('file', RNFetchBlob.wrap(file.base64), {contentType: 'image/png'})
with no luck
we try to log the form data on attach
function,
{
"_parts": [
[
"type",
"image_type"
],
[
"file",
"path/to/file"
]
]
}
it clearly show that the file
is there
calling the same api from Postman
is success without a problem
what did we do wrong here? any feedback is welcome
thank you
Superagent: v4.0.0 React Native: v0.57.5 React: v16.6.3 rn-fetch-blob: v0.10.13
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:21
Top GitHub Comments
Once again, it was our mistake, the JSON Object should be:
Thank you again
Thank you, that works!