You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that if I try to read an image file in order to retrieve magic numbers from it so I could better detect the mime type of the file, iOS doesn't appear to be friendly about it.
I am using the following code to extract the first 20 hex codes from the file:
List<int> fileBytes = File(path).readAsBytesSync().toList();
List<int> header = [];
int i = 0;
String output = '';
fileBytes.forEach((element){
if(element == 0) return;
if (i > 20) return;
output += element.toRadixString(16) + " ";
header.add(element);
i++;
});
In addition to that, I am also trying to read the file content into a string, with the code below:
Looking at the list of magic numbers this hex codes is for the WebP image file, which is correct.
Even the file content (the content variable) starts with:
However, running the same code on iOS, produces this for hex:
89 50 4e 47 d a 1a a d 49 48 44 52 2 bc 1 90 8 6 4c 3c
This corresponds to the PNG image format, which is wrong. Even the file content is incorrect, as it start as the code below:
I can say for certain that the problem is not with the iOS emulator as the same issue appears on a physical device. It is also appearing on iOS 14+ version (as I know iOS just recently introduced WebP support). Regardless, I don't believe the issue is with the image format support.
I am having a hard time understanding why the same file is being read so differently on iOS. On android, it is read exactly as it's expected, while on iOS it's like the OS is converting the file to a format it understand and gives that to the flutter app to use.
So, if there's anyone who can give me a better explanation on why this happens, I would be extremely grateful. I have also submitted this issue on the flutter bug tracker.
The text was updated successfully, but these errors were encountered:
It seems that if I try to read an image file in order to retrieve magic numbers from it so I could better detect the mime type of the file, iOS doesn't appear to be friendly about it.
I am using the following code to extract the first 20 hex codes from the file:
In addition to that, I am also trying to read the file content into a string, with the code below:
In order to replicate the issue, I am using this image as an example.
On Android the
header
variable gives me the following hex:Looking at the list of magic numbers this hex codes is for the WebP image file, which is correct.
Even the file content (the
content
variable) starts with:However, running the same code on iOS, produces this for hex:
This corresponds to the PNG image format, which is wrong. Even the file content is incorrect, as it start as the code below:
I can say for certain that the problem is not with the iOS emulator as the same issue appears on a physical device. It is also appearing on iOS 14+ version (as I know iOS just recently introduced WebP support). Regardless, I don't believe the issue is with the image format support.
I am having a hard time understanding why the same file is being read so differently on iOS. On android, it is read exactly as it's expected, while on iOS it's like the OS is converting the file to a format it understand and gives that to the flutter app to use.
So, if there's anyone who can give me a better explanation on why this happens, I would be extremely grateful. I have also submitted this issue on the flutter bug tracker.
The text was updated successfully, but these errors were encountered: