-
Notifications
You must be signed in to change notification settings - Fork 995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to download file in Android 11 (ENOENT: no such file or directory, open '/storage/emulated/0/fileName.pdf') #950
Comments
Hello do u solve the problem? |
Seriously... |
try for the permission in following way,
|
If you want to be able to download a document to android storage, you must request user permission for For older versions of android, you must add the necessary permissions from above (see below) to AndroidManifest.xml under <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="<your package name here>">
...
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
<application
....
</application>
</manifest> |
@R4DIC4L Can you please let us know up to what version of android permissions need to be mentioned in Androidmanifest.xml? |
@Yandamuri As mentioned in https://developer.android.com/guide/topics/manifest/uses-permission-element: I find it good practice to also include the permisions in the manifest since for android 5.1 and below it is easy to do and handled by the Play Store automatically at install time (you receive Granted when asking in code by default as the user acknowledges all necessary permissions when agreeing to install your app), permissions also show in the app page when you tap See permissions in About page. But you can skip this if your users must have Android 6 and above to install the app. |
Also, keep in mind that android 11 added scoped storage for apps by default and all react-native packages that I know of are not yet prepared to handle this. Until a next android version, you can opt out of this as mentioned here: https://developer.android.com/about/versions/11/privacy/storage. So you probably also need to set |
setting this solves the file download error on Android 10/11 |
Hello, since by the 5th of May Google Play will ignore this flag and remove app that do not use API like Media Store or Storage Access Framework how should we handle this? |
@marf is there any official note regarding this? if so, Can you please ping me the link? |
Hello @Yandamuri, The flag
will be ignored soon and also app uploaded with this flag enable are receiving a warning form Google about this fact. Thank you! |
Has anyone found a workaround for this? Since the May 5th deadline is pretty close.. |
@marf android/app/src/main/AndroidManifest.xml
API 30 is needed to found the flag android:preserveLegacyExternalStorage. android/build.gradle
|
The problem is that Google said that after the 5th of May this flag will be ignored since it purpose was only to help developers during this transition period which is basically ending now. |
I see the following notice in Google Play:
From what I understand, a temporary option until Storage Access is available in a react native package, we can also declare the MANAGE_EXTERNAL_STORAGE permission in the manifest (I already have READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE) and it will act as All files permission. This means the user will have to give explicit permission for the app managing their external storage as well. This probably has to be requested for newer APIs together with the other 2 when trying to access the storage. |
More details on All files access can be found here: https://developer.android.com/training/data-storage/manage-all-files#all-files-access-google-play. Has anyone tried to upload a new build to Play Store (even for internal/beta testing)? I am unsure whether this would actually work. |
Trying to tie together all the related issues to the root issue: #998 |
@R4DIC4L But I'm confused about this new storage strategy. At the moment, seems like react-native-fs doesnt work without android:requestLegacyExternalStorage="true". |
@gabrielporcher I am also using target SDK 29 with android:requestLegacyExternalStorage="true" and can confirm that you can successfully upload the app to Play Store. Yet they have notified in Play Console that after august the app will be required to target SDK 30 and android:requestLegacyExternalStorage="true" will not work anymore, forcing us to use the new scoped storage. I am also confused as I don't fully understand the Scoped Storage, nor think that any react native packages are ready for this change at this moment. |
Am unable to send a pdf despite having android:requestLegacyExternalStorage="true" as well as both WRITE_EXTERNAL_STORAGE/READ_EXTERNAL_STORAGE . Gives EACCES (Permission denied), when trying to read it with RNFS (but stat works), and unable to upload it (socket closed). |
found any solution to save files in android 11? |
August is almost over, any updates on the issue? |
android:requestLegacyExternalStorage="true" |
@AdnanAshraf7 android:requestLegacyExternalStorage="true" is working well if you are targeting Sdk29, but after August 2021 you will have to target Sdk30 where this requestLegacyExternalStorage flag will be ignored. |
Add this permission to manifest file :
Use below code to save file No need allow any storage permission in > Q for the same:
|
hello, any updates on the issue? i am also facing same issue in android 11 also Adding this to android manifest file android:requestLegacyExternalStorage="true" but no success |
Hellow everybody! Is there any solution yet? - Hope someone can help me with this, please! |
i use react-native-android-uri-path. But i dont know if it will solve all of your issues. I mostly use it for content:// files but i think it still works. import getPath from '@flyerhq/react-native-android-uri-path'; and getPath on your path to get all the absolute path |
I found the solution for myself. Hope to help someone!
|
I noticed the same error message and it had nothing to do with permissions. The problem was that I was trying to create a file with a name that was already taken on the Downloads directory. |
you can use: |
@parameshwari5 Of course, it will work. But it won't work with version 30 and Google Play require the |
Hi @trungitvn I am getting the same error for Android 10. I guess your solution might work for me, but I don't understand your code completely. Is |
For android 11 + |
@Shreyakkk Your solution seems to be working for me on Android 12. Thanks. EDIT: Throughout the day I found that if I delete a downloaded file from my device's file system, Perhaps my experience so far is not extensive enough to make any definitive conclusions, but this sure seems weird. |
@Shreyakkk Your solution works for me! |
@Shreyakkk @UVStudio @jgudo I got the same error: If I download a file for the first time it works perfectly fine. When I delete the file and download it again I get the "no such file or directory" error. I am not able to reproduce this error on every device. Do you have any solution for this besides putting Date.now() into the file name? |
@PhilippLeh21 @UVStudio Did you guys do something other than adding Date().now() to the file name? |
Hello, i have a temporary solution. You can download the file to TemporaryDirectoryPath than copying the file to the downloads folder. Here is my example. import FS from "react-native-fs"; const res = await FS.downloadFile({ if (res.statusCode !== 200) return; FileSystem.cpExternal(`${FS.TemporaryDirectoryPath}/${fileName}`, fileName, "downloads"); |
Can confirm @chizhkov422 's solution worked. I didn't copy my data but I switched on to the temp directory on the later versions of android and its working now. Wonder if its a permission issue. |
It Works!!!. Thanks. |
I am trying to download the File in Android 11 but unable to download the file. Every time it's giving ENOENT: no such file or directory, open '/storage/emulated/0/fileName.pdf' error.
FileHelper.js
The text was updated successfully, but these errors were encountered: