CSV/Text file upload using node js - node.js

I need to create a function to upload CSV/txt file into mongodb using mean stack.
The function should be like i will upload a file. First it will check whether its in text/csv format than it will upload that to mongodb.
I searched on internet and couldnt find any good material. Anyone have any idea, Please share

I used angular-file-upload and wrote my own handler using multiparty for express.

Related

Using the multer library with cloudinary api

Good day everyone.
I'm trying to upload a file to my cloudinary through a nodejs backend(already done a similar project). In my first project i followed steps on youTube tutorial using Multer and Cloudinary api. Although i don't fully understand what i did but after checking out the docs on cloudinary, i was wondering if using the multer library was necessary and why?
cloudinary.v2.uploader.upload() //uploads the file
Thanks for your contributions.
You don't need to use Multer specifically but where there's a POST request coming from your frontend form to the backend, and then you're sending a file from that backend to a remote service like Cloudinary, it's common to use some piece of middleware to take the file(s) from the form and make them available to your code for further use, and Multer is a very common library used for that purpose
There are several other libraries you could use for this instead - For example, Cloudinary's Node SDK ships with a simple web application example that uses the multiparty library via a connector, and the README for that project recommends another library called busboy for the same purpose - anything that takes multipart form data and makes the files available to your code can work here

Read Words from a PDF or DOC file in React or Firebase Cloud Functions

I have a simple React application (with no back-end servers), hosted on Firebase.
The application takes in a file(either a word document or a pdf) and stores it in firebase storage and stores the metadata in firestore.
I have a requirement to read the number of words in the file and if it is more than 500, block the upload.
I have been searching for a way to do this using just React and i think it cant be done. The other option i have is to use Cloud Functions in Firebase which use NodeJs and even with that i am not finding any solution to do this.
At this point in time, i cant setup a proper back-end server to do this work.
I would be grateful if someone can point me in the right direction to solve this.
Thanks.
A few pdf readers exist for node which can be installed in Cloud Functions since most don't support in browser. It is advised to upload the pdf to storage to save processing issues, simply add the reference path to the Cloud Function payload and delete it after completion.
pdfreader at this current time the best available for PDF's parsing, but requires a node environment such as Cloud Functions.
The second issue is reading image-based pdf's which require OCR, link provided.
https://www.npmjs.com/package/pdfreader
https://www.npmjs.com/package/pdf-ocr

Uploading an image to file system using Node.js

I am trying to upload an image to my server through a node.js server using express. I am in the process of writing an CRUD API but I am stuck on how to POST and save the image in a directory on my server.
//post
app.post('/public/media', function(req,res){
});
This is the barebones of my post method. I am trying to store the image in my media file. How should I go about this?
Note, I am not trying to store the image into a database. Rather, I am trying to store the image in a folder on my server and simply store the path to the image in my database.
Without duplicating an entire article about this issue, checkout this tutorial out. You will need to make slight adjustments to this code if using Express 4, otherwise it will work great.
Comment if you have issues below.

Saving Images to S3 from External URL with Node.js and MongoDB

I'm trying to save the images from a third-party API to my own S3 bucket using Node.js and MongoDB. The API provides a URL to the image on the third-party servers. I've never done this before but I'm assuming I have to download the image to my own server and then upload it to S3?
Should I save the image to mongodb with GridFS and then delete it once it is on S3? If so, what's the best way to do that?
I've read and re-read this previous question:
Problem with MongoDB GridFS Saving Files with Node.JS
But I can't find good documentation on how I should determine buffer/chunk size and other attributes for a JPEG image file.
Once I've saved the file on my server/database, then it seems like I should use:
https://github.com/appsattic/node-awssum
To upload it to S3. Is that a good idea?
I apologize if this is an obvious answer, I'm pretty green when it comes to databases and server scripting.
The easiest thing to do would be to save the image onto disk and then stream the upload from there using AwsSum's S3 PutObject operation. Alternatively, if you have the file contents in a Buffer you can just use that.
Have a look at the following two examples and they should help you figure out what to do:
https://github.com/appsattic/node-awssum/blob/master/examples/amazon/s3/put-bucket.js
https://github.com/appsattic/node-awssum/blob/master/examples/amazon/s3/put-object-streaming.js
Let me know if you need any more help. :)
Cheers,
Andy
Disclaimer: I'm the author of AwsSum.

Write file stream during file upload - node.js & node-formidable

Clients can upload files by using a Multi-part form post to my node.js application. To handle the file upload I'm using the node-formidable library.
Now, I manage to upload the file in chunks to node but I don't want it to be buffered before it's written to disk. So, I'm trying to understand how I can write the file data chunks to disk when they're received. I don't fully understand the node-formidable api how to acheive.
Can someone give a simple example of how to listen for an incoming file, create a file stream and then access the data coming in and write that data to the stream and finally closing the stream.
Thanks for help!
There is one example here. It doesn't use formidable library but a similar module (multipart). But it explains everything that you have asked for. You can massage it to fit you needs.
Thanks,
KA

Resources