Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit b239dfa

Browse files
committed
Add additional parameter support for #141
1 parent 1de74c1 commit b239dfa

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public RNFetchBlobFileResp(ReactApplicationContext ctx, String taskId, ResponseB
4141
assert path != null;
4242
this.mPath = path;
4343
if (path != null) {
44+
boolean appendToExistingFile = path.contains("?append=true");
4445
File f = new File(path);
4546
if(f.exists() == false)
4647
f.createNewFile();
47-
ofStream = new FileOutputStream(new File(path));
48+
ofStream = new FileOutputStream(new File(path), appendToExistingFile);
4849
}
4950
}
5051

src/ios/RNFetchBlobNetwork.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
220220
if ([response respondsToSelector:@selector(allHeaderFields)])
221221
{
222222
NSDictionary *headers = [httpResponse allHeaderFields];
223+
if(expectedBytes < 0)
224+
{
225+
expectedBytes = [[headers valueForKey:@"Content-Length"] intValue];
226+
227+
}
223228
NSString * respCType = [[RNFetchBlobReqBuilder getHeaderIgnoreCases:@"Content-Type" fromHeaders:headers] lowercaseString];
224229
if(respCType != nil)
225230
{
@@ -282,10 +287,16 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
282287
@try{
283288
NSFileManager * fm = [NSFileManager defaultManager];
284289
NSString * folder = [destPath stringByDeletingLastPathComponent];
285-
if(![fm fileExistsAtPath:folder]) {
290+
if(![fm fileExistsAtPath:folder])
291+
{
286292
[fm createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:NULL error:nil];
287293
}
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:@""];
289300
[fm createFileAtPath:destPath contents:[[NSData alloc] init] attributes:nil];
290301
}
291302
writeStream = [[NSOutputStream alloc] initToFileAtPath:destPath append:YES];

0 commit comments

Comments
 (0)