Easily differentiate video files from image files in Node - node.js

I'm building a project where people can upload files, I would like to then display those files in a browser where people can interact with them (vote, comment etc)
However, this means I need to programatically build the html depending on the format of the video or image. Is there a way to feed a file (or filename) into a library, and determine whether I need to display it in a video element or an image element? Even a list of video formats vs image formats would help but I haven't seen anything in regards to that.

No module can reliably determine the file type. The user could either change the extension or even the magic number of the file to obfuscate it. The only reliable way it to try to pass file to some image / video transcoder to let it decide or error out if the format is invalid. This way you know you are working with known formats since all files are transcoded to your specific extensions. That could be mp4 or png. I recommend using handbrake for videos and sharp for images. Leaving the NPM links down below:
https://www.npmjs.com/package/handbrake-js
https://www.npmjs.com/package/sharp

Related

how to get and display photo from ldap

I'm using ldap3.
I can connect and read all attributes without any issue, but I don't know how to display the photo of the attribute thumbnailPhoto.
If I print(conn.entries[0].thumbnailPhoto) I get a bunch of binary values like b'\xff\xd8\xff\xe0\x00\x10JFIF.....'.
I have to display it on a bottle web page. So I have to put this value in a jpeg or png file.
How can I do that?
The easiest way is to save the raw byte value in a file and open it with a picture editor. The photo is probably a jpeg, but it can be in any format.
Have a look at my answer at Display thumbnailPhoto from Active Directory in PHP. It's especially for PHP but the concept is the same for Python.
basically it's about either using the base64 encoded raw-data as data-stream or actually using a temporary file that is serverd (or used to determine the mime-type)

TCPDF - generating a PDF within browser but also playing an audio

I'm writing in raw PHP on Linux using the tcpdf library.
The core question is that while creating a PDF with tcpdf I'd also like to kick off an audio file for the user...but tcpdf considers that TCPDF ERROR: Some data has already been output, can't send PDF file so I'm looking for a way to play an audio file at PDF generation without tcpdf considering that 'interfering output'.
I can successfully generate my wanted PDF within my browser using the tcpdf library and calls. But I would also like to play an audio when this happens - that might say "This is your generated PDF. You can print it now...etc"
So I'm wanting to put the HTML audio syntax within my php script.
However if I try to include an audio clause before the tcpdf->output, tcpdf will play the audio but say that output has happened before the tcpdf output and will not generate the PDF image. Flow stops after the tcpdf->output command - it successfully generates the PDF but it does not return for additional lines so I can't place the audio line after the output call.
So I guess I'm looking for a "hidden" audio although I've tried hidden attributes within the HTML audio syntax but still tcpdf flags it as "output has happened". Thank you.
Well, obviously, you can do that simply by
generate the PDF into file (not to the client directly -- 'F' switch).
output your audio file to the client and let it platy
output a link/Javascript redirection to the generated PDF file.
Because you didn't provide any code in your question I do not provide any either, but I believe it is already understandable.

How do i get any file signature (or call it file header) in NodeJS

I am working on a module which uploads images, pdfs, audio and video files. I mainly covered all the validations in it but i am stuck at one point where i cannot detect the header of the video/audio file. It is when i change the type of any file, like changed the .JS to mp3 or mp4. Is there any packages in nodeJS which can detect the file signature or header?
Thanks in advance.
If you can not/do not, want to check by the filename extension you will have to parse the file using an appropriate media inspector.
To list a few:
file-type
mux.js

How to have node convert `.emf` to `.jpg` (or anything I can place on a webpage)

Stuck in this weird situation at work. I have .doc files I'm parsing with Node.JS. They have photos in them that are .emf I want to display in my web app. I have no issue getting the emf file out of the word doc, but I can't figure out how to display it on a webpage. Simply embedding as is didn't work. I tried to find a utility to convert them automatically but with no luck. I thought of converting them myself but can't find any tecnhical info on the .emf file.
Any suggestions?
EMF (WMF) are the SVG like formats of the 1990's.
I can't give you the full solution in this space but checkout this thread that uses Apache Batik
If you don't want to build it yourself perhaps try the paid version of converters
If you can't afford I would recommend to host the Batik and make a service endpoint and make calls to generate the desired format from EMF. It may turn out actually faster.

node.js read images from PDF

I need to use PDF in a way similar to ZIP/RAR. To hold many images (ancient tibetan buddist literature), ideally 60000. But splitting in 10-100 volumes is OK.
Anything can be used for packing, but for unpacking we need Node.js. Because same PDF file must be served on web. But some users will need to use whole PDF.
So the question is, what node module I can use to read any single arbitrary image from huge PDF? Example would really help.
Every image is a single page. (Or in otherwords every page is single image)
We have been using https://github.com/mirkokiefer/Node-Magick for this....
But the pngs we get out sometimes are fairly low quality..

Resources