L
L
LemanRass212016-10-18 14:22:46
Node.js
LemanRass21, 2016-10-18 14:22:46

How to accurately determine the type of the selected file on the disk?

The user will select a "new avatar" via the OpenDialog which will return the path to the file.
I'm loading a file from disk and sending it to a Node.js server.
On the server, I need to accurately determine that the resulting file is a picture and not something else.
I read an article on Habré: https://habrahabr.ru/post/44610/
It became scary.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2016-10-18
@LemanRass21

https://www.npmjs.com/package/mime
Also, don't forget about the accept attribute:
https://developer.mozilla.org/en-US/docs/Web/HTML/...
stackoverflow.com/questions /181214/file-input-acce...
// EDIT
https://www.npmjs.com/package/file-type

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question