question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RNFetchBlob download not working on android 9

See original GitHub issue

My code to download the file as below

RNFetchBlob
                .config({
                    path : path,
                    background: true,
                    cacheable:false,
                    timeout: 1000 * 60 * 15 //15 minutes
                })
                .fetch('GET', forFile.url, {
                    //some headers ..
                })
                .then((res) => {

                    Realm.open({schema: [ScheduleSchema,PlaylistSchema,FileSchema],schemaVersion: schema_version})
                    .then(realm => {
                        realm.write(() => {
                            localPath = Platform.OS === 'android' ? 'file://' + res.path() : `playlists/${playlistName}/${getFileName(forFile)}`
                            forFile.file_local_path = localPath
                            console.log('The file saved to ', res.path() + 'for remote url' +forFile.url)

                        })
                    }).catch((error) => {
                        alert("realm open error on file download service", error);
                        console.log(error);
                        reject(error)
                    })

                    resolve(forFile);
                }).catch((error)=>{
                    console.log("file download error " + error);
                    showToastMessage(I18n.t("ErrorMessage.ErrorInFileDownload"))
                })

This code works fine for android 7 but not on android 9. Error log from Android studio Logcat as below

java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()
        at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:164)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at com.RNFetchBlob.RNFetchBlobReq$2.intercept(RNFetchBlobReq.java:385)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:172)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)

Versions - “rn-fetch-blob”: “0.11.2” react-native: 0.60.5 Android - buildToolsVersion = “28.0.3” minSdkVersion = 22 //min supported devices, android 5.1 lollipop compileSdkVersion = 28 targetSdkVersion = 28 supportLibVersion = “28.0.3”

Note - Before the call of rn-fetch-blob file download, I have one more API call i.e fetch(react-native) to download playlists JSON.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:15
  • Comments:15

github_iconTop GitHub Comments

10reactions
JerakRuscommented, Aug 3, 2020

Кто-нибудь решил? Я не хочу использовать DownloadManager, потому что Android DownloadManager может хранить файлы только во внешнем хранилище. @JerakRus Я запросил WRITE_EXTERNAL_STORAGE, но он все еще не работает.

Сбой библиотеки, когда приложение targetSdkVersion установлено на 29, если я возвращаюсь к 28, все работает правильно.

Ошибка: E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher Process: com.test.test, PID: 6323 java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close() at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:164) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) at com.RNFetchBlob.RNFetchBlobReq$2.intercept(RNFetchBlobReq.java:433) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:172) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919)

Я думаю, что проблема в библиотеке OkHttp

try adding to <application>: android:requestLegacyExternalStorage=“true”

4reactions
JerakRuscommented, Feb 26, 2020

Guys, I solved this problem. The approach with Download Manager works because it is a third-party application that already has the required permissions. If you want to download without manager in order to get download progress, it is important to get permissions in your application. And just adding <uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" /> to AndroidManifest.xml is not enough. Additionally, you need to explicitly request permission like this: https://reactnative.dev/docs/permissionsandroid. If you do RNFetchBlob.fs.dirs - in every directory that starts with ‘/ storage’ you will need it permission! I hope someone will be useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native - RNFetchBlob download not working on android 9
My code to download the file as below RNFetchBlob.config({ path : path, background: true, cacheable:false, timeout: 1000 * 60 * 15 //15 ...
Read more >
Download a pdf with rn-fetch-blob (IOS) : r/reactnative - Reddit
Hello everyone, I have implemented a download pdf from url with react-native and rn-fetch-blob. I the download is working fine for Android.
Read more >
rn-fetch-blob-v2 - npm
A module provides upload, download, and files access API. Supports file stream read/write for process large files.. Latest version: 0.14.1, ...
Read more >
How to Download an Image in React Native from any URL
1 Image Download in React Native; 2 Features of rn-fetch-blob ... 8 Android Permission to Access Contact List; 9 Code to Download Image...
Read more >
Use rn-fetch-blob to download (background) and resume a file ...
cancel , iOS will throw an error, you can cache on it, but android is different, it will continue running next step like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found