简体   繁体   中英

Upload CSV javascript object to AWS S3 using nodejs

In my nodejs server.js file, this is what I have:

router.post('/submission', (req, res) => {
  let data_filtered = req.body.data
})

After users submit a csv, I am able to get it in my back end. Here, the format of data_filtered is:

var data_filtered = [
    {
        "Country": "Nigeria",
        "Population": "200m",
        "Continent": "Africa",
        "Official Language(s)": "English"
    },
    {
        "Country": "India",
        "Population": "1b",
        "Continent": "Asia",
        "Official Language(s)": "Hindi, English"
    }]

I am curious: how to upload this information to AWS S3 as a csv file? Any help will be useful! eg tutorials etc.

You can divide your task to 2 steps.

Step 1: Converting json to csv and storing in a file.

To accomplish this step you can use a module like json2csv and store the output into a file.

Step 2: Use aws-sdk to move the file to upload to S3

To accomplish this step you can @aws-sdk/client-s3 module to upload your file to S3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM