2

I'm using file picker for my application. In that, I want to know picked file mime type even file name has no extension. How it is possible?

Maheswari
  • 65
  • 1
  • 6

1 Answers1

2

use this package mime

You can get mime type from file path like this:

import 'package:mime/mime.dart';
....
lookupMimeType(file.path) // output: Image/Jpeg
HasilT
  • 2,463
  • 2
  • 17
  • 28
  • I have no file extensions in my file name. File name should be like this "test". not "test.jpeg". – Maheswari Sep 06 '21 at 11:10
  • @Maheswari please read this https://github.com/dart-lang/mime#determining-the-mime-type-for-a-file. if no extensions found, it will determine the mime type from the magic bytes in the beginning of the file – HasilT Sep 06 '21 at 11:23
  • @HasilT How can I find the mime type of pdf file that doesn't have a .pdf extension on the filename?? headerBytes: [0xFF, 0xD8] always return mime type as image/jpeg, so how is it possible to identify a document without any extension ?? – KJEjava48 May 23 '23 at 06:47