Browse Source

Fix multipart data format on Android #183

Ben Hsieh 8 years ago
parent
commit
ad84b9369e

+ 1
- 1
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java View File

@@ -196,7 +196,7 @@ public class RNFetchBlobBody extends RequestBody{
196 196
             // form begin
197 197
             String header = "--" + boundary + "\r\n";
198 198
             if (field.filename != null) {
199
-                header += "Content-Disposition: form-data; name=" + name + "; filename=" + field.filename + "\r\n";
199
+                header += "Content-Disposition: form-data; name=\"" + name + "\"; filename=\"" + field.filename + "\"\r\n";
200 200
                 header += "Content-Type: " + field.mime + "\r\n\r\n";
201 201
                 os.write(header.getBytes());
202 202
                 // file field header end

+ 0
- 8
src/ios/RNFetchBlobReqBuilder.h View File

@@ -29,14 +29,6 @@
29 29
                      body:(NSString *)body
30 30
                onComplete:(void(^)(NSURLRequest * req, long bodyLength))onComplete;
31 31
 
32
-+(void) buildEncodedRequest:(NSDictionary *)options
33
-                      taskId:(NSString *)taskId
34
-                      method:(NSString *)method
35
-                         url:(NSString *)url
36
-                     headers:(NSDictionary *)headers
37
-                        form:(NSString *)body
38
-                  onComplete:(void(^)(__weak NSURLRequest * req, long bodyLength))onComplete;
39
-
40 32
 +(NSString *) getHeaderIgnoreCases:(NSString *)field fromHeaders:(NSMutableArray *) headers;
41 33
 
42 34
 

+ 5
- 5
src/ios/RNFetchBlobReqBuilder.m View File

@@ -54,8 +54,8 @@
54 54
                 [request setHTTPBody:postData];
55 55
             }
56 56
             // set content-length
57
-            [mheaders setValue:[NSString stringWithFormat:@"%d",[postData length]] forKey:@"Content-Length"];
58
-            [mheaders setValue:[NSString stringWithFormat:@"100-continue",[postData length]] forKey:@"Expect"];
57
+            [mheaders setValue:[NSString stringWithFormat:@"%lu",[postData length]] forKey:@"Content-Length"];
58
+            [mheaders setValue:@"100-continue" forKey:@"Expect"];
59 59
             // appaned boundary to content-type
60 60
             [mheaders setValue:[NSString stringWithFormat:@"multipart/form-data; charset=utf-8; boundary=%@", boundary] forKey:@"content-type"];
61 61
             [request setHTTPMethod: method];
@@ -176,12 +176,12 @@
176 176
             {
177 177
                 i++;
178 178
                 getFieldData([form objectAtIndex:i]);
179
-                RCTLogWarn(@"RNFetchBlob multipart request builder has found a field without `data` or `name` property, the field will be removed implicitly.", field);
179
+                RCTLogWarn(@"RNFetchBlob multipart request builder has found a field without `data` or `name` property, the field will be removed implicitly.");
180 180
                 return;
181 181
             }
182 182
             contentType = contentType == nil ? @"application/octet-stream" : contentType;
183 183
             // field is a text field
184
-            if([field valueForKey:@"filename"] == nil || content == [NSNull null]) {
184
+            if([field valueForKey:@"filename"] == nil || content == nil) {
185 185
                 [formData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
186 186
                 [formData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n", name] dataUsingEncoding:NSUTF8StringEncoding]];
187 187
                 [formData appendData:[[NSString stringWithFormat:@"Content-Type: text/plain\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
@@ -247,7 +247,7 @@
247 247
     }
248 248
 }
249 249
 
250
-+(NSString *) getHeaderIgnoreCases:(NSString *)field fromHeaders:(NSMutableArray *) headers {
250
++(NSString *) getHeaderIgnoreCases:(NSString *)field fromHeaders:(NSMutableDictionary *) headers {
251 251
     
252 252
     NSString * normalCase = [headers valueForKey:field];
253 253
     NSString * ignoredCase = [headers valueForKey:[field lowercaseString]];