miguelpruivo / flutter_file_picker

File picker plugin for Flutter, compatible with mobile (iOS & Android), Web, Desktop (Mac, Linux, Windows) platforms with Flutter Go support.
MIT License
1.36k stars 676 forks source link

[Erro] Cannot retrieve length of file #135

Closed RenanDelfanti closed 5 years ago

RenanDelfanti commented 5 years ago

Hello, after upgrading to new version (1.4.0), I have the following problem on android via emulator: I / flutter (17036): The following FileSystemException was thrown building: I / flutter (17036): Cannot retrieve length of file, path = I / flutter (17036): '/storage/emulated/0/Android/data/br.com.xdlabs.ptme/files/DCIM/Camera/IMG_20190723_002054.jpg' (OS Error: No I / flutter (17036): such file or directory, errno = 2)

miguelpruivo commented 5 years ago

@RenanDelfanti does that happen only that file?

RenanDelfanti commented 5 years ago

@miguelpruivo no. All files I have test has the same Exception. More Example: I/flutter (31859): Cannot retrieve length of file, path = I/flutter (31859): '/storage/emulated/0/Android/data/br.com.xdlabs.ptme/files/Download/5e7e88e9-f93f-4932.jpg' (OS I/flutter (31859): Error: No such file or directory, errno = 2)

miguelpruivo commented 5 years ago

@RenanDelfanti can you post the output of your flutter doctor -v with that simulator open? Thank you.

Edit: also it would be great if you could just post all of your stack trace and not the last lines.

RenanDelfanti commented 5 years ago

Complete stack:

E/FilePickerUtils( 6037): External Document URI E/FilePickerUtils( 6037): Primary External Document URI I/FilePicker( 6037): Absolute file path:/storage/emulated/0/Android/data/br.com.xdlabs.ptme/files/Download/5e7e88e9-f93f-4932.jpg D/EGL_emulation( 6037): eglCreateContext: 0xcd3c3f00: maj 3 min 0 rcv 3 D/EGL_emulation( 6037): eglMakeCurrent: 0xcd3c3f00: ver 3 0 (tinfo 0xe8846250) D/EGL_emulation( 6037): eglMakeCurrent: 0xe2985f60: ver 3 0 (tinfo 0xc995c770) I/flutter ( 6037): Path Returned:/storage/emulated/0/Android/data/br.com.xdlabs.ptme/files/Download/5e7e88e9-f93f-4932.jpg I/flutter ( 6037): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter ( 6037): The following FileSystemException was thrown building: I/flutter ( 6037): Cannot retrieve length of file, path = I/flutter ( 6037): '/storage/emulated/0/Android/data/br.com.xdlabs.ptme/files/Download/5e7e88e9-f93f-4932.jpg' (OS I/flutter ( 6037): Error: No such file or directory, errno = 2)

My flutter doctor:

D:\Projetos\XD Labs\PTME>flutter doctor -v [√] Flutter (Channel stable, v1.7.8+hotfix.4, on Microsoft Windows [versão 10.0.18362.295], locale pt-BR) • Flutter version 1.7.8+hotfix.4 at C:\Flutter\flutter • Framework revision 20e59316b8 (6 weeks ago), 2019-07-18 20:04:33 -0700 • Engine revision fee001c93f • Dart version 2.4.0

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3) • Android SDK at C:\Users\renan\AppData\Local\Android\sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-29, build-tools 28.0.3 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03) • All Android licenses accepted.

[√] Android Studio (version 3.5) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin version 38.2.3 • Dart plugin version 191.8423 • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.37.1) • VS Code at C:\Users\renan\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.0.2

[√] VS Code, 64-bit edition (version 1.37.1) • VS Code at C:\Program Files\Microsoft VS Code • Flutter extension version 3.0.2

[√] Connected device (1 available) • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

• No issues found!

miguelpruivo commented 5 years ago

@RenanDelfanti thank you, also, could you provide me with the steps to reproduce the issue? (which filter are you applying and from which folder are you picking the file).

Does that happen with all folders?

RenanDelfanti commented 5 years ago

I have tested on real device in another project, and same issue occorred. I upload gif example here with step to reproduce this error : https://www.dropbox.com/s/jk4isocfx7mk26o/example.gif?dl=0

RenanDelfanti commented 5 years ago

Code:

file = await FilePicker.getFile(type: FileType.ANY);
int sizeInBytes = file.lengthSync();
miguelpruivo commented 5 years ago

@RenanDelfanti the .gif is static, doesn't animate. Perhaps you may want to record it again. Also, by looking at your code, looks like the exception is coming from the second line file.lenghtSync() that fails, not actually from the picker.

Anyhow, if you try with the file_picker: 1.3.8, it works?

RenanDelfanti commented 5 years ago

@miguelpruivo I just saw that dropbox is static, but when it downloads it works. I tested it on 1.3.8 and it works fine. Yes, the error is on the second line, when I will test read the file size. But this error only happens when I select internal storage, as I showed in gif

miguelpruivo commented 5 years ago

So that means that it works when you select external storage? That's an odd behavior. You can drag & drop the gif here and it should work.

RenanDelfanti commented 5 years ago

Wow, I didn't know you could put the gif here: example

miguelpruivo commented 5 years ago

@RenanDelfanti what if you chose from SDCard?

RenanDelfanti commented 5 years ago

@miguelpruivo From SDCard works normally.

miguelpruivo commented 5 years ago

@RenanDelfanti just found what might be causing the issue, but it's not quite easy to replicate and there are a few emulators that don't even allow access to the internal storage.

Anyway, I'll see what I can do tomorrow and keep you updated. Thank you!

RenanDelfanti commented 5 years ago

@miguelpruivo thank you very much! Just remembering, the same error occurred to me on a real device (Galaxy S7) Android 8.0.

miguelpruivo commented 5 years ago

Yes, that’s because I’ve updated some API calls to remove the Android 10 (API 29) deprecation warnings, however for internal storage paths, they’re not being properly retrieved, so as of now, if you really need to be able to pick internal files just stick with 1.3.8.

Nevertheless I hope to have a solution by tomorrow.

miguelpruivo commented 5 years ago

@RenanDelfanti could you please flutter clean and replace your file_picker dependency to point to the beta branch and see if it is working for you?

file_picker:
    git:
      url: https://github.com/miguelpruivo/plugins_flutter_file_picker.git
      ref: beta
RenanDelfanti commented 5 years ago

@miguelpruivo works for me

miguelpruivo commented 5 years ago

@RenanDelfanti just deployed the 1.4.0+1 on the pub.dev. You should be able to use it right now normally (file_picker: ^1.4.0+1). Feel free to reopen this if you still find anything related to it.

Thank you for reporting!

henrysoul commented 3 years ago

i have the same problem how do i solve it?