Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenfold committed Jun 7, 2022
2 parents 9d74c78 + 8876c3c commit 0ba3194
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 52 deletions.
28 changes: 28 additions & 0 deletions android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1634215444278</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
13 changes: 13 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
12 changes: 7 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:4.0.1'
}
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)
compileSdkVersion safeExtGet('compileSdkVersion', 30)
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 28)
targetSdkVersion safeExtGet('targetSdkVersion', 30)
versionCode 1
versionName "1.0"
}
Expand All @@ -40,6 +40,8 @@ android {

dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
//compile 'com.squareup.okhttp3:okhttp:+'
//{RNFetchBlob_PRE_0.28_DEPDENDENCY}
implementation "com.squareup.okhttp3:okhttp:${safeExtGet('okhttp', '+')}"
implementation "com.squareup.okhttp3:logging-interceptor:${safeExtGet('okhttp', '+')}"
implementation "com.squareup.okhttp3:okhttp-urlconnection:${safeExtGet('okhttp', '+')}"
// {RNFetchBlob_PRE_0.28_DEPDENDENCY}
}
4 changes: 2 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 01 10:33:07 BRT 2018
#Fri Aug 07 22:58:34 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
40 changes: 18 additions & 22 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
import com.facebook.react.modules.network.ForwardingCookieHandler;
import com.facebook.react.modules.network.CookieJarContainer;
import com.facebook.react.modules.network.OkHttpClientProvider;
import okhttp3.OkHttpClient;

import okhttp3.JavaNetCookieJar;
import okhttp3.OkHttpClient;

import java.io.File;
import java.util.Map;
Expand Down Expand Up @@ -108,31 +109,26 @@ public void run() {
@ReactMethod
public void actionViewIntent(String path, String mime, final Promise promise) {
try {
Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
Uri uriForFile = FileProvider.getUriForFile(this.getReactApplicationContext(),
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));

if (Build.VERSION.SDK_INT >= 24) {
// Create the intent with data and type
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(uriForFile, mime);
// Create the intent with data and type
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(uriForFile, mime);

// Set flag to give temporary permission to external app to use FileProvider
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// All the activity to be opened outside of an activity
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

// Validate that the device can open the file
PackageManager pm = getCurrentActivity().getPackageManager();
if (intent.resolveActivity(pm) != null) {
this.getReactApplicationContext().startActivity(intent);
}

} else {
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Set flag to give temporary permission to external app to use FileProvider
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// All the activity to be opened outside of an activity
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

// Validate that the device can open the file
PackageManager pm = getCurrentActivity().getPackageManager();
if (intent.resolveActivity(pm) != null) {
this.getReactApplicationContext().startActivity(intent);
} else {
promise.reject("EUNSPECIFIED", "Cannot open the URL.");
}

ActionViewVisible = true;

final LifecycleEventListener listener = new LifecycleEventListener() {
Expand Down Expand Up @@ -336,7 +332,7 @@ public void df(final Callback callback) {
fsThreadPool.execute(new Runnable() {
@Override
public void run() {
RNFetchBlobFS.df(callback);
RNFetchBlobFS.df(callback, getReactApplicationContext());
}
});
}
Expand Down Expand Up @@ -404,7 +400,7 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {

@ReactMethod
public void getSDCardDir(Promise promise) {
RNFetchBlobFS.getSDCardDir(promise);
RNFetchBlobFS.getSDCardDir(this.getReactApplicationContext(), promise);
}

@ReactMethod
Expand Down
24 changes: 12 additions & 12 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,16 @@ static Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {

res.put("DocumentDir", ctx.getFilesDir().getAbsolutePath());
res.put("CacheDir", ctx.getCacheDir().getAbsolutePath());
res.put("DCIMDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
res.put("PictureDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
res.put("MusicDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath());
res.put("DownloadDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
res.put("MovieDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
res.put("RingtoneDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES).getAbsolutePath());
res.put("DCIMDir", ctx.getExternalFilesDir(Environment.DIRECTORY_DCIM).getAbsolutePath());
res.put("PictureDir", ctx.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath());
res.put("MusicDir", ctx.getExternalFilesDir(Environment.DIRECTORY_MUSIC).getAbsolutePath());
res.put("DownloadDir", ctx.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
res.put("MovieDir", ctx.getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath());
res.put("RingtoneDir", ctx.getExternalFilesDir(Environment.DIRECTORY_RINGTONES).getAbsolutePath());
String state;
state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
res.put("SDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath());
res.put("SDCardDir", ctx.getExternalFilesDir(null).getAbsolutePath());

File externalDirectory = ctx.getExternalFilesDir(null);

Expand All @@ -276,9 +276,9 @@ static Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {
return res;
}

static public void getSDCardDir(Promise promise) {
static public void getSDCardDir(ReactApplicationContext ctx, Promise promise) {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
promise.resolve(Environment.getExternalStorageDirectory().getAbsolutePath());
promise.resolve(ctx.getExternalFilesDir(null).getAbsolutePath());
} else {
promise.reject("RNFetchBlob.getSDCardDir", "External storage not mounted");
}
Expand Down Expand Up @@ -986,13 +986,13 @@ static void createFileASCII(String path, ReadableArray data, Promise promise) {
}
}

static void df(Callback callback) {
StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
static void df(Callback callback, ReactApplicationContext ctx) {
StatFs stat = new StatFs(ctx.getFilesDir().getPath());
WritableMap args = Arguments.createMap();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
args.putString("internal_free", String.valueOf(stat.getFreeBytes()));
args.putString("internal_total", String.valueOf(stat.getTotalBytes()));
StatFs statEx = new StatFs(Environment.getExternalStorageDirectory().getPath());
StatFs statEx = new StatFs(ctx.getExternalFilesDir(null).getPath());
args.putString("external_free", String.valueOf(statEx.getFreeBytes()));
args.putString("external_total", String.valueOf(statEx.getTotalBytes()));

Expand Down
21 changes: 15 additions & 6 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ public Response intercept(Chain chain) throws IOException {
clientBuilder.addInterceptor(new Interceptor() {
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
Response originalResponse = null;
try {
Response originalResponse = chain.proceed(req);
originalResponse = chain.proceed(req);
ResponseBody extended;
switch (responseType) {
case KeepInMemory:
Expand Down Expand Up @@ -423,13 +424,21 @@ public Response intercept(@NonNull Chain chain) throws IOException {
}
catch(SocketException e) {
timeout = true;
}
catch (SocketTimeoutException e ){
if (originalResponse != null) {
originalResponse.close();
}
} catch (SocketTimeoutException e) {
timeout = true;
//RNFetchBlobUtils.emitWarningEvent("RNFetchBlob error when sending request : " + e.getLocalizedMessage());
} catch(Exception ex) {

if (originalResponse != null) {
originalResponse.close();
}
//ReactNativeBlobUtilUtils.emitWarningEvent("ReactNativeBlobUtil error when sending request : " + e.getLocalizedMessage());
} catch (Exception ex) {
if (originalResponse != null) {
originalResponse.close();
}
}

return chain.proceed(chain.request());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.content.ContentUris;
import android.os.Environment;
import android.content.ContentResolver;
import com.RNFetchBlob.RNFetchBlobUtils;
import java.io.File;
Expand All @@ -30,7 +29,7 @@ public static String getRealPathFromURI(final Context context, final Uri uri) {
final String type = split[0];

if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
return context.getExternalFilesDir(null) + "/" + split[1];
}

// TODO handle non-primary volumes
Expand Down
9 changes: 7 additions & 2 deletions ios/RNFetchBlob/RNFetchBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ - (NSDictionary *)constantsToExport
fileContent = [[NSData alloc] initWithData:[data dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]];
}
else if([[encoding lowercaseString] isEqualToString:@"base64"]) {
fileContent = [[NSData alloc] initWithBase64EncodedData:data options:0];
fileContent = [[NSData alloc] initWithBase64EncodedData:data options:NSDataBase64DecodingIgnoreUnknownCharacters];
}
else if([[encoding lowercaseString] isEqualToString:@"uri"]) {
NSString * orgPath = [data stringByReplacingOccurrencesOfString:FILE_PREFIX withString:@""];
Expand Down Expand Up @@ -639,7 +639,12 @@ - (NSDictionary *)constantsToExport
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
return window.rootViewController;
UIViewController *currentlyPresentedView = [window.rootViewController presentedViewController];
if (currentlyPresentedView == nil)
{
return window.rootViewController;
}
return currentlyPresentedView;
}

# pragma mark - check expired network events
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rn-fetch-blob",
"version": "0.13.0-beta1",
"version": "0.13.0-beta-1",
"description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions polyfill/Fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class RNFetchBlobFetchPolyfill {
promise = Blob.build(body).then((b) => {
blobCache = b
options.headers['Content-Type'] = 'multipart/form-data;boundary=' + b.multipartBoundary
options.headers['content-type'] = 'multipart/form-data;boundary=' + b.multipartBoundary
return Promise.resolve(RNFetchBlob.wrap(b._ref))
})
}
Expand Down

0 comments on commit 0ba3194

Please sign in to comment.