Use libmagic someway to detect true filetype and go from there. https://github.com/mscdex/mmmagic https://github.com/seangarner/node-stream-mmmagic