This repository was archived by the owner on Mar 16, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +15
-1
lines changed
android/src/main/java/com/RNFetchBlob Expand file tree Collapse file tree 4 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ private void writeFormData(BufferedSink sink) throws IOException {
94
94
String header = "--" + boundary + "\r \n " ;
95
95
if (field .filename != null ) {
96
96
header += "Content-Disposition: form-data; name=" + name + "; filename=" + field .filename + "\r \n " ;
97
- header += "Content-Type: " + field .mime + "\r \n \r \n " ;
97
+ header += "Content-Type: " + field .mime + "\r \n \r \n " ;
98
98
sink .write (header .getBytes ());
99
99
// file field header end
100
100
// upload from storage
Original file line number Diff line number Diff line change @@ -213,6 +213,11 @@ else if(this.options.fileCache == true)
213
213
requestType = RequestType .SingleFile ;
214
214
}
215
215
else if (cType .toLowerCase ().contains (";base64" ) || cType .toLowerCase ().startsWith ("application/octet" )) {
216
+ cType = cType .replace (";base64" ,"" ).replace (";BASE64" ,"" );
217
+ if (mheaders .containsKey ("content-type" ))
218
+ mheaders .put ("content-type" , cType );
219
+ if (mheaders .containsKey ("Content-Type" ))
220
+ mheaders .put ("Content-Type" , cType );
216
221
requestType = RequestType .SingleFile ;
217
222
} else {
218
223
requestType = RequestType .AsIs ;
Original file line number Diff line number Diff line change @@ -119,6 +119,11 @@ +(void) buildOctetRequest:(NSDictionary *)options
119
119
// when content-type is application/octet* decode body string using BASE64 decoder
120
120
if ([[cType lowercaseString ] hasPrefix: @" application/octet" ] || [[cType lowercaseString ] containsString: @" ;base64" ])
121
121
{
122
+ __block NSString * ncType = [[cType stringByReplacingOccurrencesOfString: @" ;base64" withString: @" " ]stringByReplacingOccurrencesOfString:@" ;BASE64" withString: @" " ];
123
+ if ([mheaders valueForKey: @" content-type" ] != nil )
124
+ [mheaders setValue: ncType forKey: @" content-type" ];
125
+ if ([mheaders valueForKey: @" Content-Type" ] != nil )
126
+ [mheaders setValue: ncType forKey: @" Content-Type" ];
122
127
blobData = [[NSData alloc ] initWithBase64EncodedString: body options: 0 ];
123
128
[request setHTTPBody: blobData];
124
129
size = [blobData length ];
Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ class RNFetchBlobFetchPolyfill {
47
47
// When request body is a Blob, use file URI of the Blob as request body.
48
48
else if ( body . isRNFetchBlobPolyfill )
49
49
promise = Promise . resolve ( RNFetchBlob . wrap ( body . blobPath ) )
50
+ else if ( typeof body !== 'object' )
51
+ promise = Promise . resolve ( JSON . stringify ( body ) )
52
+ else if ( typeof body !== 'string' )
53
+ promise = Promise . resolve ( body . toString ( ) )
50
54
// send it as-is, leave the native module decide how to send the body.
51
55
else
52
56
promise = Promise . resolve ( body )
You can’t perform that action at this time.
0 commit comments