0

I have created a Rest API with node js and express js. The Rest api is consumed by a cli I have created using oclif and typescript. I want to create a command that takes a csv file sends the data as multipart form data to the rest api, and the rest api imports the data in an existing table. The csv is big in data (13MB). The code I have created for the cli is the following:

else if (`${flags.newdata}` !== "undefined" && `${flags.source}` !== "undefined" ){
        var FormData=require('form-data');
        const form_data = new FormData();
        form_data.append("file", fs.createReadStream(`${flags.source}`));

        /*const request_config = {
            headers: {
                "Authorization": token,
                "Content-Type": "multipart/form-data"
        },
        data: form_data
        };*/

        return axios.post('https://localhost:8765/energy/api/Admin/' + `${flags.newdata}`, form_data);
    }

Inside this app.post there should be some code that receives the multipart form data and an sql query that imports the data in the database. How can Ido this?

  • Multipart form data simply means uploading files, possibly along with a form, so, if you searched for "how do I save images to MySQL", you'd probably find: https://stackoverflow.com/a/6472268/2430549 – HoldOffHunger Feb 24 '20 at 18:01
  • @FoggyDay yes it helps a lot thank you! –  Feb 24 '20 at 22:23

0 Answers0