Determine if a file is really an image in express/node.js - node.js

How can I check if the file uploaded on my server is really an image? Not just a file with (jpg,png,gif) extension just to make it as "an image" file. I created an image compression service using imagemin, but I'm afraid if the uploaded file is really an image.

I have used the mmmagic module for this, it discovers mime types:
mmmagic on Github

Mime types are not useful.
Try magic numbers or purely try to open the file.
Read with link for more details.
https://stackoverflow.com/a/8475542/1979882
http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html#Image

Another option is https://github.com/sindresorhus/image-type. Looks like mmmagic relies on libmagic which is a C lib and might be a lot to pull in...

Related

Autodesk Forge: Industrial Construction Demo bucket not working

I have cloned the Industrial Construction Demo code https://github.com/petrbroz/forge-industrial-construction but I am having issues with the 'bucket-name'.
In the launch file you need to specify "FORGE_BUCKET": "" instead of the usual URN.
I have written the name of the bucket that contains my file but it does not work. I have tried debugging it but still no luck.
There is no exemplary bucket or files, so I would really like to know:
-What do I need to put in as the bucket name?
-What files need to be in the bucket?
-What file types?
-Any extra information to help me figure out why it isnt working.
Many thanks,
Poppy
My apologies, I haven't explained this in the code sample very well. The demo requires files in Forge to be named in a specific way. I have just updated the README with more details: https://github.com/petrbroz/forge-industrial-construction.

collada2gltf converter can't produce *.json file

I am reading a book: Programming 3D Applications with HTML5 and WebG , it involve a Vizi framework.
All the examples load the *.json file instead of *.gltf file. Why?
When I load *.gltf, it doesn't load any result, and the collada2gltf converters only produce *.gltf, *.bin, *.glsl files and so on.
What should I do?
.gltf is a JSON file. Try to open it with a text editor and see for youself. .bin and .glsl files are just additional resources, linked from .gltf file. Those are geometry buffers and shaders respectively. So to make it work you should make sure that all the files produced with the converter are also available to a web browser you running your code in.
Also you can try to add -e CLI flag to collada2gltf and it'll embed all the resources into result .gltf file.

Thermocycle library and OpenModelica

I want to load Thermocycle library by OpenModelica connect edition. But I get a message "The file was not encoded in UTF-8"
To fix this problem I should: "add a file package.encoding at the top-level." But I don't understand what must I do? What is the file which called "package.encoding", what should this file consist from? Where should I insert it?
The error message says it all. "add a file package.encoding at the top-level."
Put the file where your library's package.mo is located.
The file must contain the name of encoding used by the library.
Note that you can also use OMEdit's encoding conversion feature. File->Open/Convert Modelica File(s) With Encoding

Deal with ZIP-Buffer in node.js

I am building the server part of a webapp, using node.js. This involves getting data from thetvdb.com (API documentation of thetvdb).
The data comes as a zip file. HTTP download is no problem, however, parsing the file is. I actually never save the file, but just keep it in memory, as suggested in How to download and unzip a zip file in memory in NodeJs?
I have a buffer with valid data (same data as when I download the file with browser/curl...). However, adm-zip (I also tired other zip libraries, some suggest invalid zip length) can't open it. It does not show an error, but the zipEntries in the end have length of 0.
When I write out the buffer to the filesystem and open it with gui or cli tools it works.
I can't give a direkt link to the file, as it would involve my API key, however I re-uploaded it here.
I think I might have an answer for you:
Don't rely on npm install. I just ran the example that you linked to with the zip file you provided, and I get an output of "0".
I saw a comment on that other StackOverflow page, saying that the version of adm-zip on npm is not up to date. I grabbed a fresh copy of adm-zip from github, overwrote the one in my node_modules folder and reran the example code and now get the following:
...
<Actor>
<id>237811</id>
<Image>actors/237811.jpg</Image>
<Name>Peter Pratt</Name>
<Role>The Master</Role>
<SortOrder>3</SortOrder>
</Actor>
<Actor>
<id>23780s/237811.jpg</Image>
Give that a shot!

Open Files Created with BSAVE in QuickBasic?

I have some files that were created using BSAVE in QuickBasic. I'm wondering how I can load/view these files?
I received assistance over at the FreeBasic forums. Its easy to do if you download and install the FreeBasic compiler / IDE. Here is the relevant thread:
http://www.freebasic.net/forum/viewtopic.php?t=12554&postdays=0&postorder=asc&start=0
Essentially, it loads the image using BLOAD like one normally would and then BSAVEs it as a BMP. I suppose it would be pretty easy to create an app. that did this by just prompting for source and output files...
I would try installing pcpaint (free) http://www.shdon.com/software/pcpaint
Change the extension to .PIC and try to open it. Apparently this program used bsave to save images with the extention .pic.
Hope this works!

Resources