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

#555 Cancel download throw error bugfix (Android) #568

Open
wants to merge 8 commits into
base: 0.10.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ RNFetchBlob
console.log('The file saved to ', res.path())
// Beware that when using a file path as Image source on Android,
// you must prepend "file://"" before the file path
imageView = <Image source={{ uri : Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path() }}/>
imageView = <Image source={{ uri : Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path() }}/>
})
```

Expand Down
4 changes: 2 additions & 2 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ else if (value.equalsIgnoreCase("utf8"))
}
}

if(method.equalsIgnoreCase("post") || method.equalsIgnoreCase("put") || method.equalsIgnoreCase("patch")) {
if(method.equalsIgnoreCase("post") || method.equalsIgnoreCase("put") || method.equalsIgnoreCase("patch") || method.equalsIgnoreCase("delete")) {
String cType = getHeaderIgnoreCases(mheaders, "Content-Type").toLowerCase();

if(rawRequestBodyArray != null) {
Expand Down Expand Up @@ -316,7 +316,7 @@ else if(cType.isEmpty()) {
break;

case WithoutBody:
if(method.equalsIgnoreCase("post") || method.equalsIgnoreCase("put") || method.equalsIgnoreCase("patch"))
if(method.equalsIgnoreCase("post") || method.equalsIgnoreCase("put") || method.equalsIgnoreCase("patch") || method.equalsIgnoreCase("delete"))
{
builder.method(method, RequestBody.create(null, new byte[0]));
}
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,13 @@ function fetch(...args:any):Promise {
}

// from remote HTTP(S)
let promiseResolve;
let promiseReject;

let promise = new Promise((resolve, reject) => {
promiseResolve = resolve;
promiseReject = reject;

let nativeMethodName = Array.isArray(body) ? 'fetchBlobForm' : 'fetchBlob'

// on progress event listener
Expand Down Expand Up @@ -370,6 +376,7 @@ function fetch(...args:any):Promise {
subscriptionUpload.remove()
stateEvent.remove()
RNFetchBlob.cancelRequest(taskId, fn)
promiseReject(new Error("canceled"))
}
promise.taskId = taskId

Expand Down
7 changes: 3 additions & 4 deletions ios/RNFetchBlobReqBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ +(void) buildOctetRequest:(NSDictionary *)options
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSMutableData * blobData;
long size = -1;
// if method is POST, PUT or PATCH, convert data string format
if([[method lowercaseString] isEqualToString:@"post"] || [[method lowercaseString] isEqualToString:@"put"] || [[method lowercaseString] isEqualToString:@"patch"]) {
// if method is POST, PUT, PATCH or DELETE, convert data string format
if([[method lowercaseString] isEqualToString:@"post"] || [[method lowercaseString] isEqualToString:@"put"] || [[method lowercaseString] isEqualToString:@"patch"] || [[method lowercaseString] isEqualToString:@"delete"]) {
// generate octet-stream body
if(body != nil) {
__block NSString * cType = [[self class] getHeaderIgnoreCases:@"content-type" fromHeaders:mheaders];
Expand All @@ -117,7 +117,6 @@ +(void) buildOctetRequest:(NSDictionary *)options
orgPath = [RNFetchBlobFS getPathOfAsset:orgPath];
if([orgPath hasPrefix:AL_PREFIX])
{

[RNFetchBlobFS readFile:orgPath encoding:nil onComplete:^(id content, NSString* code, NSString * err) {
if(err != nil)
{
Expand All @@ -131,7 +130,7 @@ +(void) buildOctetRequest:(NSDictionary *)options
onComplete(request, [((NSData *)content) length]);
}
}];

return;
}
size = [[[NSFileManager defaultManager] attributesOfItemAtPath:orgPath error:nil] fileSize];
Expand Down