瀏覽代碼

Change native content type checking logic

Ben Hsieh 8 年之前
父節點
當前提交
04b7785a86

+ 1
- 1
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java 查看文件

@@ -94,7 +94,7 @@ public class RNFetchBlobBody extends RequestBody{
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

+ 5
- 0
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java 查看文件

@@ -213,6 +213,11 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
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;

+ 5
- 0
src/ios/RNFetchBlobReqBuilder.m 查看文件

@@ -119,6 +119,11 @@
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];

+ 4
- 0
src/polyfill/Fetch.js 查看文件

@@ -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)