Import data from a CSV file
Last updated
Was this helpful?
Last updated
Was this helpful?
This example shows you how to create a Smart Action "Import data"
to import data from a CSV file.
Forest Admin natively supports data creation but it’s sometimes more efficient to simply import it.
An admin backend running on forest-express-sequelize/forest-express-mongoose
This directory contains the products.js
file where the model is declared.
This directory contains the products.js
file where the Smart Action Import data
is declared.
This directory contains the products.js
file where the implementation of the route is handled. The POST /forest/actions/import-data
API call is triggered when you click on the Smart Action in the Forest UI.
You may find below the coding examples you need to make this Smart action work:
For large file uploads, you should add an option in your Express Server in your app.js file:
npm package
npm package
npm package
The CSV file passed into the body of the API call is serialized using a base64 encoding .
To deserialize the base64 encoded CSV file, we use the NPM package . We also use the NPM package to iterate over each line of the CSV file.
You can find a sample CSV file we use here to feed our products table on the .