0

I'm trying to upload an xlsx to firestore storage ,I'm using react-native-document-picker to pick the file from ExternalStorageDirectoryPath so when just log the files uri I don't get the error but as soon as try to upload the file it throws the error .
relevant code :

 const uploadFile=async ()=>{
        try {
          
            const res = await DocumentPicker.pick({
                type: [DocumentPicker.types.allFiles],
            });
           
            const task =  Storage().ref('catalogue/'+ res.name).putFile(res.uri);
           
            task.on('state_changed', 
                sn =>{},
                err=>console.log(err),
                () => {
                   console.log('excel uploaded!'+res.name)
                   Storage()
                   .ref("catalogue").child(res.name).getDownloadURL()
                   .then(url => {
                     console.log('uploaded excel url', url);
                   }).catch(err=>console.log(err))
               }
            )
            await task 
             
           
          } catch (err) {
            if (DocumentPicker.isCancel(err)) {
              // User cancelled the picker, exit any dialogs or menus and move on
            } else {
              throw err;
            }
        }
    }

` I already included the required permissions in my AndroidManifest.xml file and rebuilt the project

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>

but still I'm getting this error :

Permission Denial: reading com.android.externalStorageProvider uri content://com... requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()

سعيد
  • 1,301
  • 8
  • 25
  • There are two AndroidManifest files in react-native. Double check that you have it in the root file, and also, it might be worth doing a clean install of the app or checking it's permissions granted in the settings. – nipuna777 Feb 15 '21 at 00:48
  • This answer may help you https://stackoverflow.com/a/60316149/7178860 – Mohammad Feb 15 '21 at 06:23

1 Answers1

1

I had a similar problem with the frameworks Qt with the last android SDK version, I've fixed the problem by adding requestLegacyExternalStorage in the manifest (pat Application):

<application android:requestLegacyExternalStorage="true" android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" //...

it's related to a recent change in the permission system: https://developer.android.com/about/versions/11/privacy/storage

Zeeshan Ansari
  • 7,835
  • 2
  • 25
  • 25
Antoine Laps
  • 101
  • 5