瀏覽代碼

Add warning message when form data format incorrect #90

Ben Hsieh 8 年之前
父節點
當前提交
7090203686
共有 2 個檔案被更改,包括 6 行新增1 行删除
  1. 4
    1
      src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java
  2. 2
    0
      src/ios/RNFetchBlobReqBuilder.m

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

@@ -291,7 +291,10 @@ public class RNFetchBlobBody extends RequestBody{
291 291
             FormField field = new FormField(form.getMap(i));
292 292
             list.add(field);
293 293
             String data = field.data;
294
-            if (field.filename != null) {
294
+            if(data == null) {
295
+                RNFetchBlobUtils.emitWarningEvent("RNFetchBlob multipart request builder has found a field without `data` property, the field `"+ field.name +"` will be removed implicitly.");
296
+            }
297
+            else if (field.filename != null) {
295 298
                 // upload from storage
296 299
                 if (data.startsWith(RNFetchBlobConst.FILE_PREFIX)) {
297 300
                     String orgPath = data.substring(RNFetchBlobConst.FILE_PREFIX.length());

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

@@ -11,6 +11,7 @@
11 11
 #import "RNFetchBlobNetwork.h"
12 12
 #import "RNFetchBlobConst.h"
13 13
 #import "RNFetchBlobFS.h"
14
+#import "RCTLog.h"
14 15
 
15 16
 @interface RNFetchBlobReqBuilder()
16 17
 {
@@ -165,6 +166,7 @@
165 166
             {
166 167
                 i++;
167 168
                 getFieldData([form objectAtIndex:i]);
169
+                RCTLogWarn(@"RNFetchBlob multipart request builder has found a field without `data` or `name` property, the field will be removed implicitly.", field);
168 170
                 return;
169 171
             }
170 172
             contentType = contentType == nil ? @"application/octet-stream" : contentType;