Qubaish Bhatti Qubaish Bhatti - 26 days ago 14
Node.js Question

saving image file in mongodb using node gm (graphic magic)

I am totally new in node and mongodb concepts. I am trying to save the image, file (meta data) saved successfully but its chunks are not saving.

I also read gm documentation but did not helped alot plus i am not facing any error. https://github.com/aheckmann/gm

here is my code

var writeStream = gfs.createWriteStream({
filename: file.name,
mode: 'w',
content_type: file.type,
metadata: {
uid: uid,
createdAt: Date.today().setTimeToNow()
}
});
gm(file.data).resize(200).filter('Catrom').quality(80).stream().pipe(writeStream);


and here is my file object which i am passing

file : { data: "blob:http://localhost:3000/2664926c-f5e3-4ed2-8c3e-0473fd759944", name: "photo.jpg", type: "image/jpeg"}


Help much appreciated :)

Answer

Finally I found the issue, we have to write the blob url after piping. Here is the change

gm(file.data).resize(200).filter('Catrom').quality(80).stream().pipe(writeStream).write(file.data);

Thanks :)

Comments