2

So, this is my problem. I read from some APIs a URL that points to a file. The only thing I know about this file is that it is a file... but I would like to detect what kind of file this is. The URL is not helping since it is encoded in base64 (I guess) and so I have no file name or extension I could use for my scope.

I have tried to use node-mime module (https://github.com/broofa/node-mime) but what I get is application/octet-stream which is not that much useful in detecting the real type of the file.

The aim is to display "in browser" the files that the browser is able to handle without requiring the user to download them.

Thanks!

2
  • 1
    "URL that points to a file", so obviously you can get a filename from URL, right? Decode it ( Node.js supports base64 decoding ) and use node-mime afterwards. If you can't decode it, then this is impossible to be done. Commented Sep 25, 2012 at 16:36
  • Just to add to that - "obviously" isn't that obvious when you deal with optimized servers that don't return extensions for media files... Commented Feb 22, 2018 at 13:35

4 Answers 4

3

If you want to display the files in browser itself without the need to download use 'Content-Disposition: inline' header.

Sign up to request clarification or add additional context in comments.

1 Comment

this is helping. but now I have find out that those files are .zip files, so I should unzip them and then display them... trying to make it working!
3

mmmagic will work, but requires an external library (libmagic) or Python equivalent. This presents problems if you do not want to install Python on your Windows machine. It would be nice to have a pure node version of libmagic.

1 Comment

Did you ever find a pure node library?
2

Use mmmagic to determine the mime type.

https://npmjs.org/package/mmmagic

Comments

0
request({ url: fb_media.media_url, encoding: null }, async function (err, res, body) { const mimeType = res.headers['content-type']; const fileSize = res.headers['content-length']; }) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.