express-fileupload:get check size in express js - node.js

I am using this package
to upload the image into server ,i want to check the file size before upload but express-fileupload doesn't give any information about it
console.log(req.files.image); it returns only the name,data ,and image type

Assuming the name of your file in your HTML file is image, req.files.image.data.length will give you the buffer length in bytes. See this Node.js. API Documentation for more details. You can then do the math to convert the number of bytes into any thing you want.
This will allow you to get the actual number of bytes independent of filetype and doesn't require using the mv function. So you can use this on any file type not just images.
Hopefully this helps!

I think only way to get image info using express-fileupload is using mv function to move image on server then using image-size to get width and height

Related

AWS Rekognition: Requested image should either contain bytes or s3 object

I am doing a mock content moderation labeling using AWS Rekognition on React, but no matter what available image format (bytes, S3 object) I submitted, Rekognition never recognizes it, giving Unhandled Rejection (InvalidParameterException): Requested image should either contain bytes or s3 object.
I have followed Rekognition's guideline here, StackOverflow solutions: 1. Converting into Bytes as an Image param here, 2. Using S3 Object here, 3. Using Buffer to read image here, 4. Using raw file input to upload image (this one definitely did not work), 5. Checking if my image is corrupted or not here – in fact I tried with more than 20 images and all failed, 6. Stripping EXIF data here.
Library I use: node-rekognition (I use an old package because my huge node app is still runs on version 12.13.0), React 16 (class component approach)
Feel free to request any additional info if I lack some. Thanks.

Can't get to exif data .JPG image

I'm trying to read the exif data from a .JPG image. I've tried differents solutions found here and there (PIL, piexif, exifread...) and none of them worked for this set of images. It worked for other images taken from another camera but not for this one, all these different methods returning empty dictionaries. It seems that there is no exif data but (I apologies for my newbyness) when I RIGHT-click + properties (I use windows), I do see what is exif data to me : date of creation, etc...
Here is one image :
image.JPG
If another of the thousands of anonymous heroes could help me on this one, I would be very grateful...
Alright so I found a solution which I share now.
The problem is that the libraries that open metadata are not taking all possible configurations for the image file and therefore, they can handle some and some others they cannot. I finally made it using exiftool, an executable that I dowloaded on my windows on this link :
https://sno.phy.queensu.ca/~phil/exiftool/
Then I paste the executable in a folder and I add exiftool.py in that folder, that I got from :
https://github.com/smarnach/pyexiftool/find/master
Then, using this small piece of code (for example):
import exiftool
with exiftool.ExifTool("exiftool.exe") as et:
metadata = et.get_metadata_batch(files)
for d in metadata:
print("{:20.20} {:20.20}".format(d["SourceFile"],
d["File:FileCreateDate"]))
Of course, this is just to show that you indeed can access the metadata, then you can do whatever you want with that. Here is the documentation of the library exiftool : http://smarnach.github.io/pyexiftool/
Cheers, JM

Is it possible to get actual cropped PNG from Croppie instead of the base64 encoding?

I am using Croppie to crop an image and it is giving me base64 which creates 413 error while sending it on server for large images, so I need proper image file. I tried to find converting it(base64) as a image file locally at client side but didn't get expected way for conversion using javascript/jquery.
Please guide me.

How do I check the size of a file in Node.js?

So, I have a file (jpg, tiff or pdf) which initially is represented as a base64-encoded string, which I create a buffer from.
Now I want to check the size of given file without writing it to filesystem first.
I am using Node v4.4.3 on Linux.
How could I go about doing this?
Use Buffer.byteLength function.

Highcharts PhantomJS export SVG as base64

I have a question regarding generating an SVG instead of an PNG serverside using PhantomJS. I have PhantomJS running as a server and am POSTing JSON to it (http://www.highcharts.com/docs/export-module/render-charts-serverside). I would like to receive an SVG represented as a BASE64 result stream. I am running in some problems however.
I tried both the following requests, but the base64 result would always represent a png file:
{"infile":".......", "type":"image/svg+xml"}
And:
{"infile":".......", "type":"svg"}
I do however get a valid svg file when I use the outfile parameter:
{"infile":".......", "type":"svg", "outfile":"anActualSVG.svg"}
This writes a file to disk, which is not what I am looking for.
Does anyone have some suggestions?
Thanks!

Resources