File upload node.js express - node.js

I am using Node JS as web API server, for the front end, I am using Angular 4, Android and IOS. I have successfully implemented file upload using post request. I am exposing only one port outside. I need to implement file upload with a progress bar. I have only worked with POST and GET requests in past.I am not getting how to implement it on the server and send the progress responses to the front end. Additionally is there any other method that can be used.
It would be of great help if someone could help me with this process

For file upload you can use DropzoneJS. Since you are using Angular for front end use Dropzone for Angular.

I was looking into it and heard socket.io can be used to achieve the same. i need to user sharp package on the streamed data

For the server side, I use the built in express routers using multer. Multer parses multipart form data and uses callbacks that play very nicely with express routers.
Then for the UI you need an element that can upload multipart form data. If your using HTML 5 then you should be able to use just about any library that is out there. I personally use Vaadin uploads. It's a nice drop in element that does all the work for you. It even has a nice upload bar and status built in.

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

How can I use react with a custom webserver?

I want to use React for a project I am working on, but I also want to use an API.
How can I do it?
I have tried to Google this and ask different people, but I have not got a response yet, so I thought I would ask here. I want to use express and maybe not use create-react-app (as it takes up a lot of storage).
Working on a custom server doesen't preclude the use of an API.
If you want fetch the API from the express server and inject it directly on react frontend you need to enable server side rendering (useful post) and pass the data collected as a props from the server (check this example).
Rather then you can build your react project (using even create-react-app) and build an express server who return the index.html on call.
Personally I prefer the first one solution.

How to get reference from an html element in nodejs?

I just started with nodejs and since I can't reference the app.js to the html file since I'm actually starting that js file with the nodejs. Is there a way to achieve this?
It doesn't work like that. I think you are trying to use the app.js file of a node app as if it was a simple script reference in the html with the tags.
NodeJS runs in the server and the HTML file runs in the client. The server script you are running can provide data to the client, client-server must be "connected" with an API.
If you are using vue or react for the Front-End, check Axios as a library for fetching data via API.
Check this tutorial
It's a detailed and great explanation for what you need.

Use nodeJS server with symfony

I have a huge symfony app and I wanted to add some feature that I could only do with a nodeJS server .
So I have a big JSON file which result from my nodeJS run, this file have to go in Symfony.
And symfony have to be able to send some pdf file to the node server (the one which will be transform in JSON by my node server).
Is anyone have some starting idea ?
thansk for help :D
No one is going to be able to provide a full answer with so few details, but generally speaking messaging and remote procedure calls are excellent for interop between parts of a large app.
You could send a message from Symfony (which includes the path of the PDF, or the contents itself), and node will provide the result. You can encode that as JSON, and send it as an answer.
RabbitMq is widely supported, allows both produce-consume or RPC-style use.

Using fineuploader in node.js

I have a fineuploader server set up which handles uploads from the browser using the fineuploader library. I can't seem to find anywhere if I can upload from node.js as well. Is this possible? Can I create a Blob and pass it to fineuploader?
Fine Uploader is a browser-based upload tool. It was never designed to work server-side. If you'd like to send requests from a Node server, there are a number of library focused on that particular workflow, such as the request library.

Resources