Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve OS Error: Permission denied, errno = 13 in flutter

Tags:

flutter

I am new in Flutter. I want to store my document file into '/storage/emulated/0/Download/'. I have error about Unhandled Exception: FileSystemException: Cannot open file, path = '/storage/emulated/0/Download/file.pdf' (OS Error: Permission denied, errno = 13)

Here is my code:

void download() async {
http.Response response = await http.post(url, headers: {"Accept": "application/json", HttpHeaders.authorizationHeader: 'Bearer}});

  File file = new File('/storage/emulated/0/Download/file.pdf');
  await file.writeAsBytes(response.bodyBytes);
}
like image 337
qing Avatar asked Mar 06 '20 06:03

qing


2 Answers

In Android Q, you need to add the Following Lines in AndroidManifest file:

 <application
      android:requestLegacyExternalStorage="true"
like image 190
Rajil TL Avatar answered Sep 19 '22 13:09

Rajil TL


Just add the following lines in to your android manifest if you're on android 10/Q

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
   <application
        android:requestLegacyExternalStorage="true"
    >
like image 28
Charith Jayasanka Avatar answered Sep 19 '22 13:09

Charith Jayasanka