-
Notifications
You must be signed in to change notification settings - Fork 1.6k
How to add boundary when uploading file to server #105
Comments
@siyuan , the boundary will be automatically append to |
I've just tested on both Android and IOS with let tmp = null
// create an image file
RNFetchBlob
.config({ fileCache : true })
.fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
.then((res) => {
tmp = res.path()
// send multipart request with file
return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
'Content-Type' : 'multipart/form-data'
}, [
{ name : 'file', filename : 'github.png', data : RNFetchBlob.wrap(tmp) }
])
})
.then((res) => {
done()
}) and here's the log at server
|
My code, response.uri is the picture address of other module tcpdump: 'content-length' is missing. |
I think the problem is not missing boundary, the request header does not have a Besides, I've also noticed that the request is sent using I think you may try install latest version and see if that solves this problem.
Thank you ! |
Thank you very much. But when I use react-native-fetch-blob, I can't find this log. Maybe the connection is not closed? |
Not sure what's the root cause, from my understanding, keepalive connection does not close when task is done, instead it reuses the connection sending multiple request for better perofrmance. I'm wondering if that's because the |
This is the curl tcpdump data. I use tcpdump on my Linux host. not the same picture |
Would it possible the problem is the absence of Another difference I saw is the |
Hi, |
I simply use Express and its middleware multer for testing multipart requests. You can check out the test-server of this project 👍 Also we've tested the multipart request heavily on Firebase. |
The root cause of my problem is my server's filename needs "
|
I use the following code to upload file
RNFetchBlob.fetch('POST', 'http://www.example.com/upload-form', {
Authorization : "Bearer access-token",
otherHeader : "foo",
// this is required, otherwise it won't be process as a multipart/form-data request
'Content-Type' : 'multipart/form-data',
},
{
name : 'avatar',
filename : 'avatar.png',
// Change BASE64 encoded data to a file path with prefix
RNFetchBlob-file://
.// Or simply wrap the file path with RNFetchBlob.wrap().
data: RNFetchBlob.wrap(PATH_TO_THE_FILE)
}
)
This method fails to upload file because missing boundary. I tried to add boundary after multipart/form-data, still failed to upload.
The text was updated successfully, but these errors were encountered: