Sfoglia il codice sorgente

Fix IOS writeFile behavior

Ben Hsieh 8 anni fa
parent
commit
c2985f4245

+ 1
- 0
src/ios/RNFetchBlob/RNFetchBlob.m Vedi File

@@ -192,6 +192,7 @@ RCT_EXPORT_METHOD(closeStream:(NSString *)streamId callback:(RCTResponseSenderBl
192 192
     callback(@[[NSNull null], @YES]);
193 193
 }
194 194
 
195
+#pragma mark - unlink
195 196
 RCT_EXPORT_METHOD(unlink:(NSString *)path callback:(RCTResponseSenderBlock) callback) {
196 197
     NSError * error = nil;
197 198
     NSString * tmpPath = nil;

+ 1
- 0
src/ios/RNFetchBlobFS.m Vedi File

@@ -225,6 +225,7 @@ NSMutableDictionary *fileStreams = nil;
225 225
             [os open];
226 226
             while((read = [asset getBytes:buffer fromOffset:cursor length:10240 error:nil]) > 0)
227 227
             {
228
+                cursor += read;
228 229
                 [os write:buffer maxLength:read];
229 230
             }
230 231
             __block NSNumber * size = [NSNumber numberWithLong:written];

+ 17
- 7
src/ios/RNFetchBlobReqBuilder.m Vedi File

@@ -36,12 +36,12 @@
36 36
     
37 37
     // send request
38 38
     __block NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: encodedUrl]];
39
-    NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[RNFetchBlobNetwork normalizeHeaders:headers]];
39
+    __block NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[RNFetchBlobNetwork normalizeHeaders:headers]];
40 40
     NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
41 41
     NSNumber * timeStampObj = [NSNumber numberWithDouble: timeStamp];
42 42
 
43 43
     // generate boundary
44
-    NSString * boundary = [NSString stringWithFormat:@"RNFetchBlob%d", timeStampObj];
44
+    __block NSString * boundary = [NSString stringWithFormat:@"RNFetchBlob%d", timeStampObj];
45 45
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
46 46
         __block NSMutableData * postData = [[NSMutableData alloc] init];
47 47
         // combine multipart/form-data body
@@ -148,7 +148,7 @@
148 148
 
149 149
 +(void) buildFormBody:(NSArray *)form boundary:(NSString *)boundary onComplete:(void(^)(NSData * formData))onComplete
150 150
 {
151
-    NSMutableData * formData = [[NSMutableData alloc] init];
151
+    __block NSMutableData * formData = [[NSMutableData alloc] init];
152 152
     if(form == nil)
153 153
         onComplete(nil);
154 154
     else
@@ -159,7 +159,7 @@
159 159
         void __block (^getFieldData)(id field) = ^(id field)
160 160
         {
161 161
             NSString * name = [field valueForKey:@"name"];
162
-            NSString * content = [field valueForKey:@"data"];
162
+            __block NSString * content = [field valueForKey:@"data"];
163 163
             NSString * contentType = [field valueForKey:@"type"];
164 164
             // skip when the form field `name` or `data` is empty
165 165
             if(content == nil || name == nil)
@@ -197,10 +197,14 @@
197 197
                             i++;
198 198
                             if(i < count)
199 199
                             {
200
-                                getFieldData([form objectAtIndex:i]);
200
+                                __block NSDictionary * nextField = [form objectAtIndex:i];
201
+                                getFieldData(nextField);
201 202
                             }
202 203
                             else
204
+                            {
203 205
                                 onComplete(formData);
206
+                                getFieldData = nil;
207
+                            }
204 208
                         }];
205 209
                         return ;
206 210
                     }
@@ -213,17 +217,23 @@
213 217
                 [formData appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", contentType] dataUsingEncoding:NSUTF8StringEncoding]];
214 218
                 [formData appendData:blobData];
215 219
                 [formData appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
220
+                blobData = nil;
216 221
             }
217 222
             i++;
218 223
             if(i < count)
219 224
             {
220
-                getFieldData([form objectAtIndex:i]);
225
+                __block NSDictionary * nextField = [form objectAtIndex:i];
226
+                getFieldData(nextField);
221 227
             }
222 228
             else
229
+            {
223 230
                 onComplete(formData);
231
+                getFieldData = nil;
232
+            }
224 233
 
225 234
         };
226
-        getFieldData([form objectAtIndex:i]);
235
+        __block NSDictionary * nextField = [form objectAtIndex:i];
236
+        getFieldData(nextField);
227 237
     }
228 238
 }
229 239