Skip to content

Commit 7335923

Browse files
author
Ron Radtke
committed
Merge remote-tracking branch 'origin/develop' into feature/media_collections
# Conflicts: # android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java # index.d.ts
2 parents f83212f + 74e5cc1 commit 7335923

File tree

9 files changed

+44
-28
lines changed

9 files changed

+44
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ In `v0.5.0` we've added `writeStream` and `readStream`, which allows your app r
651651

652652
When calling `readStream` method, you have to `open` the stream, and start to read data. When the file is large, consider using an appropriate `bufferSize` and `interval` to reduce the native event dispatching overhead (see [Performance Tips](#user-content-performance-tips))
653653

654-
> The file stream event has a default throttle(10ms) and buffer size which preventing it cause too much overhead to main thread, yo can also [tweak these values](#user-content-performance-tips).
654+
> The file stream event has a default throttle(10ms) and buffer size which preventing it cause too much overhead to main thread, you can also [tweak these values](#user-content-performance-tips).
655655
656656
```js
657657
let data = ''

android/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ dependencies {
6363
}
6464

6565
afterEvaluate { project ->
66+
// do this only when building this lib alone as a root project
67+
if (project != rootProject) {
68+
return
69+
}
70+
6671
// some Gradle build hooks ref:
6772
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
6873
task androidJavadoc(type: Javadoc) {

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,37 +118,29 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
118118
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));
119119

120120
Intent intent = new Intent(Intent.ACTION_VIEW);
121-
if (Build.VERSION.SDK_INT >= 24) {
121+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
122122
// Create the intent with data and type
123123
intent.setDataAndType(uriForFile, mime);
124-
if (chooserTitle != null) {
125-
intent = Intent.createChooser(intent, chooserTitle);
126-
}
127124

128125
// Set flag to give temporary permission to external app to use FileProvider
129126
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
130127
// All the activity to be opened outside of an activity
131128
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
132-
133-
// Validate that the device can open the file
134-
PackageManager pm = getCurrentActivity().getPackageManager();
135-
if (intent.resolveActivity(pm) != null) {
136-
this.getReactApplicationContext().startActivity(intent);
137-
}
138-
139129
} else {
140130
intent.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
141-
if (chooserTitle != null) {
142-
intent = Intent.createChooser(intent, chooserTitle);
143-
}
131+
}
144132

145-
try {
146-
this.getReactApplicationContext().startActivity(intent);
147-
promise.resolve(true);
148-
} catch (ActivityNotFoundException ex) {
149-
promise.reject("ENOAPP", "No app installed for " + mime);
150-
}
133+
if (chooserTitle != null) {
134+
intent = Intent.createChooser(intent, chooserTitle);
151135
}
136+
137+
try {
138+
this.getReactApplicationContext().startActivity(intent);
139+
promise.resolve(true);
140+
} catch (ActivityNotFoundException ex) {
141+
promise.reject("ENOAPP", "No app installed for " + mime);
142+
}
143+
152144
ActionViewVisible = true;
153145

154146
final LifecycleEventListener listener = new LifecycleEventListener() {

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void writeFile(String path, String encoding, String data, final boolean a
5757

5858
if (!f.exists()) {
5959
if (dir != null && !dir.exists()) {
60-
if (!dir.mkdirs()) {
60+
if (!dir.mkdirs() && !dir.exists()) {
6161
promise.reject("EUNSPECIFIED", "Failed to create parent directory of '" + path + "'");
6262
return;
6363
}
@@ -129,7 +129,7 @@ static void writeFile(String path, ReadableArray data, final boolean append, fin
129129

130130
if (!f.exists()) {
131131
if (dir != null && !dir.exists()) {
132-
if (!dir.mkdirs()) {
132+
if (!dir.mkdirs() && !dir.exists()) {
133133
promise.reject("ENOTDIR", "Failed to create parent directory of '" + path + "'");
134134
return;
135135
}
@@ -445,7 +445,7 @@ void writeStream(String path, String encoding, boolean append, Callback callback
445445

446446
if (!dest.exists()) {
447447
if (dir != null && !dir.exists()) {
448-
if (!dir.mkdirs()) {
448+
if (!dir.mkdirs() && !dir.exists()) {
449449
callback.invoke("ENOTDIR", "Failed to create parent directory of '" + path + "'");
450450
return;
451451
}

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ private void done(Response resp) {
598598
ReactNativeBlobUtilFileResp ReactNativeBlobUtilFileResp;
599599

600600
try {
601-
ReactNativeBlobUtilFileResp = (ReactNativeBlobUtilFileResp) responseBody;
601+
ReactNativeBlobUtilFileResp = new ReactNativeBlobUtilFileResp(responseBody);
602602
} catch (ClassCastException ex) {
603603
// unexpected response type
604604
if (responseBody != null) {

android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilFileResp.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class ReactNativeBlobUtilFileResp extends ResponseBody {
3535
FileOutputStream ofStream;
3636
boolean isEndMarkerReceived;
3737

38+
public ReactNativeBlobUtilFileResp(ResponseBody body) {
39+
super();
40+
this.originalBody = body;
41+
}
42+
3843
public ReactNativeBlobUtilFileResp(ReactApplicationContext ctx, String taskId, ResponseBody body, String path, boolean overwrite) throws IOException {
3944
super();
4045
this.rctContext = ctx;

index.d.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,23 @@ export interface FS {
436436
slice(src: string, dest: string, start: number, end: number): Promise<void>;
437437

438438
asset(path: string): string;
439+
df(): Promise<RNFetchBlobDf>;
440+
}
441+
442+
export interface RNFetchBlobDfIOS {
443+
free?: number;
444+
total?: number;
445+
}
439446

440-
df(): Promise<{ free: number, total: number }>;
447+
export interface RNFetchBlobDfAndroid {
448+
external_free?: string;
449+
external_total?: string;
450+
internal_free?: string;
451+
internal_total?: string;
441452
}
442453

454+
export type RNFetchBlobDf = RNFetchBlobDfIOS & RNFetchBlobDfAndroid;
455+
443456
export interface Dirs {
444457
DocumentDir: string;
445458
CacheDir: string;
@@ -555,7 +568,7 @@ export interface AndroidApi {
555568
* @param mime Basically system will open an app according to this MIME type.
556569
* @param chooserTitle title for chooser, if not set the chooser won't be displayed (see [Android docs](https://developer.android.com/reference/android/content/Intent.html#createChooser(android.content.Intent,%20java.lang.CharSequence)))
557570
*/
558-
actionViewIntent(path: string, mime: string, chooserTitle?: string): Promise<any>;
571+
actionViewIntent(path: string, mime: string, chooserTitle?: string): Promise<boolean | null>;
559572

560573
/**
561574
*

ios/ReactNativeBlobUtilReqBuilder.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ +(void) buildOctetRequest:(NSDictionary *)options
115115
if([body hasPrefix:FILE_PREFIX]) {
116116
__block NSString * orgPath = [body substringFromIndex:[FILE_PREFIX length]];
117117
orgPath = [ReactNativeBlobUtilFS getPathOfAsset:orgPath];
118+
orgPath = [[NSURL URLWithString:orgPath] path];
118119
if([orgPath hasPrefix:AL_PREFIX])
119120
{
120121

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-blob-util",
3-
"version": "0.13.16",
3+
"version": "0.13.18",
44
"description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)