Skip to content

Commit 1715169

Browse files
author
Ron Radtke
committed
Merge remote-tracking branch 'origin/develop' into feature/media_collections
# Conflicts: # android/build.gradle # android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java
2 parents 406cbb9 + 20ab54e commit 1715169

File tree

5 files changed

+64
-48
lines changed

5 files changed

+64
-48
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ After `0.10.3` you can install this package directly from Github
8181
# replace <branch_name> with any one of the branches
8282
npm install --save github:RonRadtke/react-native-blob-util#<branch_name>
8383
```
84+
**Okhttp**
85+
86+
For using the library okhttp3 is required. It's in general included in react-native.
87+
The library uses the okhttp version shipped with react-native or used by your app.
88+
For very old devices android devices okhttp 3.12 can be used.
8489

8590
**Manually Link Native Modules**
8691

android/build.gradle

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apply plugin: 'com.android.library'
2-
apply plugin: 'maven'
2+
apply plugin: 'maven-publish'
33

44
def safeExtGet(prop, fallback) {
55
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
@@ -50,54 +50,27 @@ android {
5050
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
5151
}
5252
}
53+
lintOptions {
54+
abortOnError false
55+
}
5356
productFlavors {
5457
}
5558
}
5659

5760
dependencies {
5861
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
59-
implementation 'com.squareup.okhttp3:okhttp:3.12.+'
60-
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.+'
61-
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.12.+'
6262
implementation 'org.apache.commons:commons-lang3:3.0'
6363
}
6464

65-
def configureReactNativePom(def pom) {
66-
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
67-
68-
pom.project {
69-
name packageJson.title
70-
artifactId packageJson.name
71-
version = packageJson.version
72-
group = "com.ReactNativeBlobUtil"
73-
description packageJson.description
74-
url packageJson.repository.baseUrl
75-
76-
licenses {
77-
license {
78-
name packageJson.license
79-
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
80-
distribution 'repo'
81-
}
82-
}
83-
84-
developers {
85-
developer {
86-
id packageJson.author.username
87-
name packageJson.author.name
88-
}
89-
}
90-
}
91-
}
92-
9365
afterEvaluate { project ->
9466
// some Gradle build hooks ref:
9567
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
9668
task androidJavadoc(type: Javadoc) {
9769
source = android.sourceSets.main.java.srcDirs
98-
classpath += files(android.bootClasspath)
99-
classpath += files(project.getConfigurations().getByName('compile').asList())
100-
include '**/*.java'
70+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
71+
classpath += files(android.libraryVariants.collect { variant ->
72+
variant.javaCompileProvider.get().classpath.files
73+
})
10174
}
10275

10376
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
@@ -107,8 +80,7 @@ afterEvaluate { project ->
10780

10881
task androidSourcesJar(type: Jar) {
10982
classifier = 'sources'
110-
from android.sourceSets.main.java.srcDirs
111-
include '**/*.java'
83+
from android.sourceSets.main.java.sourceFiles
11284
}
11385

11486
android.libraryVariants.all { variant ->
@@ -125,12 +97,41 @@ afterEvaluate { project ->
12597
archives androidJavadocJar
12698
}
12799

128-
task installArchives(type: Upload) {
129-
configuration = configurations.archives
130-
repositories.mavenDeployer {
131-
// Deploy to react-native-event-bridge/maven, ready to publish to npm
132-
repository url: "file://${projectDir}/../android/maven"
133-
configureReactNativePom pom
100+
publishing {
101+
publications {
102+
mavenJava(MavenPublication) {
103+
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
104+
105+
artifactId packageJson.name
106+
groupId = "com.ReactNativeBlobUtil"
107+
version = packageJson.version
108+
109+
pom {
110+
name = packageJson.title
111+
description = packageJson.description
112+
url = packageJson.repository.baseUrl
113+
114+
licenses {
115+
license {
116+
name = packageJson.license
117+
url = packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
118+
distribution = 'repo'
119+
}
120+
}
121+
122+
developers {
123+
developer {
124+
id = packageJson.author.username
125+
name = packageJson.author.name
126+
}
127+
}
128+
}
129+
}
130+
}
131+
repositories {
132+
maven {
133+
url = "file://${projectDir}/../android/maven"
134+
}
134135
}
135136
}
136137
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,9 @@ public Response intercept(@NonNull Chain chain) throws IOException {
392392
@NonNull
393393
@Override
394394
public Response intercept(@NonNull Chain chain) throws IOException {
395+
Response originalResponse = null;
395396
try {
396-
Response originalResponse = chain.proceed(req);
397+
originalResponse = chain.proceed(req);
397398
ResponseBody extended;
398399
switch (responseType) {
399400
case KeepInMemory:
@@ -422,12 +423,21 @@ public Response intercept(@NonNull Chain chain) throws IOException {
422423
return originalResponse.newBuilder().body(extended).build();
423424
} catch (SocketException e) {
424425
timeout = true;
426+
if (originalResponse != null) {
427+
originalResponse.close();
428+
}
425429
} catch (SocketTimeoutException e) {
426430
timeout = true;
431+
if (originalResponse != null) {
432+
originalResponse.close();
433+
}
427434
//ReactNativeBlobUtilUtils.emitWarningEvent("ReactNativeBlobUtil error when sending request : " + e.getLocalizedMessage());
428-
} catch (Exception ignored) {
429-
435+
} catch (Exception ex) {
436+
if (originalResponse != null) {
437+
originalResponse.close();
438+
}
430439
}
440+
431441
return chain.proceed(chain.request());
432442
}
433443
});

fetch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export function fetch(...args: any): Promise {
259259
if (options.path || options.fileCache || options.addAndroidDownloads
260260
|| options.key || options.auto && respInfo.respType === 'blob') {
261261
if (options.session)
262-
session(options.session).add(data);
262+
fs.session(options.session).add(data);
263263
}
264264
respInfo.rnfbEncode = rawType;
265265
resolve(new FetchBlobResponse(taskId, respInfo, data));

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.12",
3+
"version": "0.13.16",
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)