How to download a pdf file (stream) from GridJs - node.js

Im trying to download a pdf file stored in mongodb using gridfs andmulter , I am recieving a stream back which when I downloaded and open the pdf file would be corrupted here is my backend for downloading it [My backend is node js and frontend is react js ].
here is my backend code
here is my frontend code
here is the response that i recieved
this is what the response.data would look like
lastly this is what the error looks like when I opened one of those downloaded files
please do help me out ive been struggling in the past two days to find a solution to this

Related

multipart/form-data fetch post gives random output and multer can't extract file

I tried to upload an image file to my server. My client is writing with react native and server is node. I use fetch POST and multipart/form-data on the client side, and multer on server side. When I tried to console.log the request, I got a tons of trash information. I followed the example provided online so I have no idea what's going on. Also multer doesn't extract file from request (req.file is undefined). Also I don't really understand if you post local uri instead of base64 data to your server. How does the server know how to retrieve upload the file through local uri.

Store file in PostgreSQL database using NodeJS and Angular2+

I have read a lot of examples/tutorials on internet that explain how to upload and store files in PostgreSQL using NodeJS, Multer, Sequelize, Express, ...
With none of them I have understood how to do it in my project.
I have an Angular app where I have an input file, I have an API in NodeJS using pg-promise to link with my PostgreSQL database. I have done all my project api with pg-promise so I would like to use it and no Sequelize.
In the database I have read that the best is probably the BYTEA type for files like jpg, png, pdf, docx...
Here is my API hierarchy :
www file contains code to initiate the server
app.js file contains code to initiate express app and the require([library]) of what I need
index.js file contains code to link urls to function that are stored in queries.js
The only thing I want is How to store a file.
Thanks if you can help me
I strongly recommend you the use of multer library. It helps you with the storage of files in disk. You get the path where it is stored, and you could save the path on the database.
https://github.com/expressjs/multer

From uploading CSV file to saving him as JSON in mongodb in server side node.js && react.js web application

I'm building node.js web application using react.js on client side and mongoDB, and I'm trying to upload a CSV file, sending it to the server side as Formdata object.
On the server side, I need to open the CSV file locally and convert it to JSON object so I could deploy the data in my mongoDB storage.

how to upload a file (excel or csv) this should read the file in nodejs and update in the database mongodb

how to upload a file which should except only excel or csv file and read the file by using nodejs and update in the database table (mongodb)
front end = angular5
backend = nodejs and mongodb
Please help me with this issue.
On the server side i.e node You will need Multer to upload files and set type to uploaded files, fs (Node Inbuilt) library to work with files, You will need csv package to parse data in that file, Mongoose-ODM to save that to MongoDB.
Next time be specific with your answer and show what you have tried till now.

Meteor JS and TinyPNG API to compress uploaded PNG

I'm trying to recompress a PNG after upload and crop using tinyPNG API https://tinypng.com/developers/reference
My HTTP request in the server method looks like :
var tinyResponse = HTTP.post('https://api.tinypng.com/shrink', {auth: 'api:<myAPIkey>', data: image});
Where image is the base64 data like : data:image/png;base64,iVBORw0KG...
The api then tels me : "Does not appear to be a PNG file"
So I guess the TinyPNG API doesn't like the base64 format. What I should do is store the base64 into a temp file, use the API to compress, get the file back and re-encode it in base64. Yes what I want is to store the image file in the mongodb directly.
But my knowledge of node.js and Meteor is not suffisant for the moment.
Can someone throw me a bone here ? Thx
(Maybe I'm totally wrong and should use GM and cfs packages)
It would be nice if you provided more code or even your github repo but check the documentation for node: https://tinypng.com/developers/reference#node-js
You can use NPM packages with Meteor: http://docs.meteor.com/#/full/Npm-depends

Resources