0

I have some input files of different mimetypes that get uploaded and then dynamically routed. The dynamic routing is determined by the mimetype of the input file. These types goes beyond standard things like application/json, xml and extend to geospatial file mimetypes, etc.

My question is, how do I determine the mimetype from an input file? Does the browser somehow auto-resolve it when it gets uploaded? Do I need to parse the input stream in my backend code using some fancy IO lib?

John Lippson
  • 1,269
  • 5
  • 17
  • 36
  • The original file name often is in the headers, as maybe the mime type (à la Content-Type). Otherwise there are the first bytes, called a **magic cookie**, There also is `Files.probeContentType` (with some issues). Best do a further web search. – Joop Eggen Jul 24 '18 at 14:25
  • Depends on the files themself. The files can all get uploaded as octetstream and you can open each file and read the file header, in case it contains the file type. If the files themself do not contain their type in the header, you need to come up with some other identification method. – Korashen Jul 24 '18 at 14:28

0 Answers0