-
Notifications
You must be signed in to change notification settings - Fork 699
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
Missing Bytes #616
Comments
Update. If I wrap my if (await Permission.storage.request().isGranted) {
// Call FilePicker.platform.pickFiles in here
} |
@cranst0n oddly permissions are being asked before launching the picker itself which isn't launched unless the permissions are actually conceded. I'll close this for now, but reopen if anyone else experiences the same. Thank you! |
@miguelpruivo I meant to post another update but must've slipped my mind. My last comment doesn't seem to be true, I must have not tracked my situation properly. I'm still hitting this issue. |
@cranst0n weird then. By looking at Android's source everything is being done properly. One cannot access file explorer without first allowing access to the content. I don't really get why you can only access it on the second access though. Which Android version are you trying on? |
Android 11. I'll try again to recreate the issue next time I'm in front of a computer. |
@miguelpruivo I've revisited this and can confirm I'm still running into this. I've tried using both local files on the phone, as well as picking files from Google Drive. Picking the file the first time fails to include bytes, in both scenarios and succeeds in subsequent picks. |
@cranst0n ill give it a try. |
Just an FYI, running the same code on ios works fine for me. |
I have this problem as well. For me this happens on the first call as well as occasionally without a noticeable pattern. |
As a workaround, I added a check to see if the bytes are missing, and then manually read them from the file. |
I don't see a reason why this should happen. Looks like those "Android nuances" that can't be properly replicated. If you manage to replicate this perfectly, please, provide me with a sample so I can work in a fix — or at least, give me the steps. Thank you. |
Same here
Can you share us this workaround? |
@altrdev Something along the lines of what I have below. final result = await FilePicker.platform.pickFiles(
withData: true,
);
if ((result.files.single.bytes ?? []).isEmpty) {
// Special case on Android, the bytes don't seem to come through
// on the first picker call
final file = File.fromUri(Uri.parse(result.files.single.path!));
final fileBytes = file.readAsBytesSync();
// Work with fileBytes...
} |
thanks @cranst0n . I do others test and my issue is slightly different. Picking the file the first time fails to include some bytes. So in my case
|
found this on Android as well |
This is quite interesting. I suspect that it could be something related with the data codec when transporting data through the platform channel, since the file should be properly read on the Android end. Could someone please provide a replicable example, since it’s not easy to replicate this edge cases? Or at least, if you’re experiencing it, debug it on your end by checking the bytes on the Android side and then on Flutter’s so we can further investigate? Thank you. |
Also, experience the same issue. Only for the first time after permission was asked. |
Please, provide me with the steps to reproduce this so I can easily try to implement a fix. |
This is happening to me as well, here is some code and information: Try to reproduce this using the following code AND the steps: CODE:FilePickerResult result = await FilePicker.platform.pickFiles(
type: FileType.image,
allowCompression: false,
allowMultiple: true,
withData: true,
);
if (result == null || result.count == 0) return;
var cnt = 0;
for (var asset in result.files) {
cnt++;
var imageData = asset.bytes;
print('imageData.lengthInBytes $cnt: ${imageData.lengthInBytes}');
} STEPS
The byte length will be different. I clarify to follow these steps, because, it seems that this happens the first time you pick the image that you never picked before, sometimes even the second time, but eventually it will read the image completely, and once it does return all the bytes it will return them every time, and then you need to file a new fie. It happens to me every single time with PNG images, I would recommend testing it with newly created screenshots. The only consistent message in the console when this happens is:
But I don't know if it's related or not. Flutter doctor:
Device: Pixel 3XL Android 11 If you require more information, let me know :) |
Ok, I was able to replicate this and there was a minor optimisation that could be done and hence prevent this issue. The fix will be deployed today. |
Using
3.0.0-nullsafety.2
Describe the bug
When picking a file with
withData
set to true, the result has no bytes on the first pick (i.e. when permission is asked for and granted). Subsequent calls return a file with the expected bytes.Platform
Platform OS version
Android 11
How are you picking?
Details to reproduce the issue
Only seems to be an issue on first call.
Error Log
No apparent errors or meaningful output.
Flutter Version details
The text was updated successfully, but these errors were encountered: