react-native-blob-util icon indicating copy to clipboard operation
react-native-blob-util copied to clipboard

Multiple files created on downloading a single file - Android < 11 - copyToMediaStore

Open javapyscript opened this issue 2 years ago • 5 comments

Version: 0.18.6 RN version: 0.71 Android: 9 (same issue on 8.1 too) Device: Nexus 6P emulator

Hello,

I am trying to download a file to the Downloads folder and am seeing three files after download. Two valid files, one with proper name and one with escaped chars. And the third file is a 0kb file

image

Code for downloading file:

if (Platform.OS === 'ios') { ReactNativeBlobUtil.ios.openDocument(response.data); } else { try { await ReactNativeBlobUtil.MediaCollection.copyToMediaStore( { name: docName, parentFolder: '', mimeType: mimeType, }, 'Download', response.path(), ); } catch (err) { console.log(err); }

The code is working fine for Android 11 and greater. Is there something I am doing wrong here? Thank you.

javapyscript avatar Aug 04 '23 05:08 javapyscript

The code works for Android 9 if I change the save path to LegacyDownloadDir instead. Its just the copyToMediaStore that seems to have this issue.

javapyscript avatar Aug 04 '23 05:08 javapyscript

The copy to mediastore should technically mimic the behavior of storing a file normally. So it looks like a bug

RonRadtke avatar Aug 04 '23 15:08 RonRadtke

Thank you. Is there any other way to download a file to Downloads folder for older Androids? I mentioned earlier that I was able to use LegacyDownloadDir, but that only copies a binary file.

javapyscript avatar Aug 09 '23 20:08 javapyscript

Basically something like this:

        .config({
            // response data will be saved to this path if it has access right.
            path: dirs.LegacyDownloadDir+ '/path-to-file.anything',
            transform: true
        })
        .fetch('GET', 'http://www.example.com/file/example.zip', {
            //some headers ..
        })
        .then((res) => {
            // the path should be dirs.LegacyDownloadDir+ 'path-to-file.anything'
            console.log('The file saved to ', res.path())
        })```

But that depends on the Android version if it works (scoped stroage and all these chagnes)

RonRadtke avatar Aug 10 '23 09:08 RonRadtke

Thanks for the reply. I will have a look at this.

javapyscript avatar Aug 16 '23 08:08 javapyscript