Fetch: Downloader.FileDownloaderType.PARALLEL doesn't support cloud locattion when using SAF

Created on 4 Jun 2019  路  11Comments  路  Source: tonyofrancis/Fetch

 private OkHttpDownloader getOkHttpDownloader() {
        return new OkHttpDownloader(okHttpClient, Downloader.FileDownloaderType.PARALLEL);
    }

 final FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(this)
                .enableLogging(BuildConfig.DEBUG)
                .setDownloadConcurrentLimit(3)
                .enableRetryOnNetworkGain(true)
                .enableAutoStart(false)
                .setAutoRetryMaxAttempts(10)
                .setProgressReportingInterval(1100)
                .setHttpDownloader(getOkHttpDownloader())
                .build();
        Fetch.Impl.setDefaultInstanceConfiguration(fetchConfiguration);

Fetch 3.1.1 AndroidX version.

When I try to download any file to cloud locations using SAF (Storage Access Framework) such as Google Drive, Box, etc, fetch returns UNKNOWN_IO_ERROR. But it works when using Downloader.FileDownloaderType.SEQUENTIAL.

I guess that it is the limitation of PARALLEL mode. But it would be great if the library does like below...

if (cloud_location)
   use_sequential_download_regardless_of_settings;
else
   use_default_fetch_config;

or can you give us the ability to change download type on the fly per download request?

bug help wanted

All 11 comments

@jpvs0101 What you can do is override the getRequestFileDownloaderType(request: ServerRequest, supportedFileDownloaderTypes: Set<Downloader.FileDownloaderType>): FileDownloaderType method on the Downloader and only return the FileDownloaderType.SEQUENTIAL type in the set. The download manager will use that information to download the request. In that method you can do checks on the url etc. Hope this helps.

Sorry, when I did several test with different versions of android, both emulator & real device, most of the time google drive not working! In Box, sometimes works, sometimes not works! No clear logs to trace the issue. You can always reproduce this issue! I can't get it what is going on...

I will have a chance to give this a try over the weekend.

@jpvs0101 I was able to pin point the error. java.io.FileNotFoundException: Unsupported mode: rw. Changed context.contentResolver.openFileDescriptor(uri, "rw") to context.contentResolver.openFileDescriptor(uri, "w") and it worked. The ContentProvider documentation does not have the updated modes. I was able to successfully use the Parallel downloader. Look out for the next release.

Awesome, you always rocks! Also please consider reducing permissions #284

@jpvs0101 had a look at issue #284 again. My position still stands. The library depends on the network state permissions defined to get network change notifications. It is actually the ConnectivityManager that require these permissions not the library.

@jpvs0101 new version of fetch is now available. See readme and changelog.

@jpvs0101 had a look at issue #284 again. My position still stands. The library depends on the network state permissions defined to get network change notifications. It is actually the ConnectivityManager that require these permissions not the library.

I understand that it was tightly coupled, but it would be great if we can use only android.permission.INTERNET & all other permissions are optional. So we can add permissions only if we use a particular feature. You can even set internet permission as optional when we use only local files.

For example, in my case, i don't check whether the connectivity is on or off, or user using wifi or not. We just throw an error when no connectivity. Simple for users & developers. So other permissions are unnecessary. Users watch permissions very closely these days but most are don't know the difference between android.permission.INTERNET & android.permission.ACCESS_NETWORK_STATE. Some users thought that the app is spying on network state. Same for fetch notification broadcast receiver. I am not using it. But it has an entry in manifest.

I hope you aware of that Android Q removed storage permission. They are restricting permissions more & more. They already put restriction on wifi scanning. So may be they restrict access network/wifi state permission in future. It is better we can prepare now. Like i mention, logically this lib can work without a permission. You give us almost everything optional & extensible except these permissions. Hope it shows an overview of the situation. Thanks!

@jpvs0101 new version of fetch is now available. See readme and changelog.

Not working with Google Drive, but works with Box. I tried various platforms, sequential, parallel, preallocation. But none works with Google drive. It shows download complete, then upload complete, but the file in google drive shows 0 bytes. Logs are normal.

If it works with box and local storage the issue is then with gDrive. You may want to look at the documentation.

OK, it is weird, I close this issue for now, I will come back later!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VitorAndrioli picture VitorAndrioli  路  4Comments

jpvs0101 picture jpvs0101  路  5Comments

MohammadFneish7 picture MohammadFneish7  路  4Comments

gbirk picture gbirk  路  5Comments

jpvs0101 picture jpvs0101  路  5Comments