|
@@ -220,6 +220,11 @@ NSOperationQueue *taskQueue;
|
220
|
220
|
if ([response respondsToSelector:@selector(allHeaderFields)])
|
221
|
221
|
{
|
222
|
222
|
NSDictionary *headers = [httpResponse allHeaderFields];
|
|
223
|
+ if(expectedBytes < 0)
|
|
224
|
+ {
|
|
225
|
+ expectedBytes = [[headers valueForKey:@"Content-Length"] intValue];
|
|
226
|
+
|
|
227
|
+ }
|
223
|
228
|
NSString * respCType = [[RNFetchBlobReqBuilder getHeaderIgnoreCases:@"Content-Type" fromHeaders:headers] lowercaseString];
|
224
|
229
|
if(respCType != nil)
|
225
|
230
|
{
|
|
@@ -282,10 +287,16 @@ NSOperationQueue *taskQueue;
|
282
|
287
|
@try{
|
283
|
288
|
NSFileManager * fm = [NSFileManager defaultManager];
|
284
|
289
|
NSString * folder = [destPath stringByDeletingLastPathComponent];
|
285
|
|
- if(![fm fileExistsAtPath:folder]) {
|
|
290
|
+ if(![fm fileExistsAtPath:folder])
|
|
291
|
+ {
|
286
|
292
|
[fm createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:NULL error:nil];
|
287
|
293
|
}
|
288
|
|
- if (![fm fileExistsAtPath:destPath]) {
|
|
294
|
+ BOOL appendToExistingFile = [destPath RNFBContainsString:@"?append=true"];
|
|
295
|
+ // For solving #141 append response data if the file already exists
|
|
296
|
+ // base on PR#139 @kejinliang
|
|
297
|
+ if (appendToExistingFile && ![fm fileExistsAtPath:destPath])
|
|
298
|
+ {
|
|
299
|
+ destPath = [destPath stringByReplacingOccurrencesOfString:@"?append=true" withString:@""];
|
289
|
300
|
[fm createFileAtPath:destPath contents:[[NSData alloc] init] attributes:nil];
|
290
|
301
|
}
|
291
|
302
|
writeStream = [[NSOutputStream alloc] initToFileAtPath:destPath append:YES];
|