I’m developing a Flutter app where I need to differentiate between image and video files. However, I’ve run into a peculiar issue: my client has this video file saved from WhatsApp, and when picking it in the app, it is seen as an image instead of a video.
He sent me the file via Google Drive & Slack, and the video was a .mp4 on both of them (which was working fine when I tried myself).
However on my client’s iphone, when printing the path of the video it was ending with “.jpeg”.
Here’s my code to determinate if it’s a video or an image :
// true if image
// false if video
// Read the first 12 bytes of the file
final List<int> headerBytes = await file.openRead(0, 12).first;
final String? mimeType =
lookupMimeType(file.path, headerBytes: headerBytes);
if (mimeType == null || !mimeType.startsWith('image/')) {
return false;
}
return true;
}
The extension should not matter, and a platform like Stack did see it as a video, so what am I doing wrong here?
Is my way of getting headerBytes correct?
I’ve tried with and without header bytes, but same result
Yoann Faraus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.