Skip to content

OS Error: Permission denied, errno = 13 when reading a File from internal storage #19504

@jnhk

Description

@jnhk

Hi, I'm trying to read an image file which I uploaded to internal storage through Device File Explorer (on Android emulator) and I ran into a permission error. However, I do not have any problem reading/writing the (image) file I downloaded from the web/localhost.

Note: I am new to mobile development and not sure whether this problem falls under the scope of flutter project, or any other. I suspect that I may be missing a configuration or two on AVD. If this is the case, any pointer to a documentation is really appreciated. Also, if it is more appropriate to post this to SO, I will close this issue and will repost there.

Steps to Reproduce

  1. Access the file using path_provider API as suggested in the cookbook :
  Future<String> get _localPath async {
    final directory = await getApplicationDocumentsDirectory();
    return directory.path;
  }

  Future<Image> getImage(int id) async {
    final path = await _localPath;
    File image = File('$path/$id.jpeg'); // 1.jpeg
    return Image.file(image);
  }

  // Widget
  FutureBuilder(
    future: getImage(1),
    builder: (BuildContext context, AsyncSnapshot<Image> snapshot) {
      return snapshot.hasData ? snapshot.data : Container();
    }
  ),
  1. Ensure that the file exist and has read permission on Device File Explorer.
    filename: '/data/user/0/<package>/app_flutter/1.jpeg'
    permission: -rw-rw-rw-
    I also modified the user/group to be similar with other files and granted full permissions.

  2. This is unrelated, but I also tried adding external storage permissions in AndroidManifest.xml.

Logs

  • console
W/1.ui    ( 6196): type=1400 audit(0.0:30): avc: denied { open } for path="/data/data/<package>/app_flutter/1.jpeg" dev="dm-0" ino=16899 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0 tclass=file permissive=0
I/flutter ( 6196): ══╡ EXCEPTION CAUGHT BY SERVICES ╞══════════════════════════════════════════════════════════════════
I/flutter ( 6196): The following FileSystemException was thrown resolving an image codec:
I/flutter ( 6196): Cannot open file, path = '/data/user/0/<package>/app_flutter/1.jpeg' (OS Error: Permission denied, errno = 13)
I/flutter ( 6196): When the exception was thrown, this was the stack:
I/flutter ( 6196): #0      _File.open.<anonymous closure> (dart:io/file_impl.dart:368:9)
I/flutter ( 6196): (elided 8 frames from package dart:async)
I/flutter ( 6196): 
I/flutter ( 6196): Path: /data/user/0/<package>/app_flutter/1.jpeg
  • flutter analyze
No issues found! (ran in 2.9s)
  • flutter doctor
[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.6 17G65, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
[✓] Android Studio (version 3.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: crashStack traces logged to the consoleengineflutter/engine repository. See also e: labels.platform-androidAndroid applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions