Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 04b7785

Browse files
committed
Change native content type checking logic
1 parent 3373932 commit 04b7785

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void writeFormData(BufferedSink sink) throws IOException {
9494
String header = "--" + boundary + "\r\n";
9595
if (field.filename != null) {
9696
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";
9898
sink.write(header.getBytes());
9999
// file field header end
100100
// upload from storage

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ else if(this.options.fileCache == true)
213213
requestType = RequestType.SingleFile;
214214
}
215215
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);
216221
requestType = RequestType.SingleFile;
217222
} else {
218223
requestType = RequestType.AsIs;

src/ios/RNFetchBlobReqBuilder.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ +(void) buildOctetRequest:(NSDictionary *)options
119119
// when content-type is application/octet* decode body string using BASE64 decoder
120120
if([[cType lowercaseString] hasPrefix:@"application/octet"] || [[cType lowercaseString] containsString:@";base64"])
121121
{
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"];
122127
blobData = [[NSData alloc] initWithBase64EncodedString:body options:0];
123128
[request setHTTPBody:blobData];
124129
size = [blobData length];

src/polyfill/Fetch.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class RNFetchBlobFetchPolyfill {
4747
// When request body is a Blob, use file URI of the Blob as request body.
4848
else if (body.isRNFetchBlobPolyfill)
4949
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())
5054
// send it as-is, leave the native module decide how to send the body.
5155
else
5256
promise = Promise.resolve(body)

0 commit comments

Comments
 (0)