Flatfile.io CSV Importer Adapter
A simple adapter for elegantly importing CSV files via flatfile.io (Typescript, ES6, Browser)
Read the developer docs → https://developers.flatfile.io/docs/install
License Key
In order to setup, you need to create or sign in to your flatfile.io account and obtain a license key.
Using NPM
If you don't like external dependencies, or you have a nice build system like Webpack in place. You can install and use Flatfile as an npm package.
npm install flatfile-csv-importer --save
Using CDN
The latest version of the package is available via CDN so you can just drop it into your website and start using it.
https://unpkg.com/flatfile-csv-importer/build/dist/index.min.js
Quickstart
Add the following code before the ending </body>
tag in your html.
<script src="https://unpkg.com/flatfile-csv-importer/build/dist/index.min.js"></script> <script> var LICENSE_KEY = 'PASTE YOUR KEY HERE' var importer = 'demo-account' fields: label: 'Robot Name' key: 'name' label: 'Shield Color' key: 'shieldColor' validator: /^[a-zA-Z]+$/ label: 'Robot Helmet Style' key: 'helmetStyle' label: 'Call Sign' key: 'sign' alternates: 'nickname' 'wave' validator: /^\w{4}$/ type: 'Robot' importer /** * Use this function to do something with your data like upload it your server * * @param data An array of objects matching your earlier configuration * [ * { * name: 'R2D2', * shieldColor: 'blue', * helmetStyle: 'awesome', * callSign: 'beep' * } * ... * ] */ { } </script>
ES6 / Babel
// configure your flatfile options hereconst options = {} // Obtain your license key from https://flatfile.ioconst LICENSE_KEY = 'PASTE YOUR KEY HERE' // initialize the importerconst importer = FLATFILE_LICENSE_KEY options // setup your handlerconst buttonClickHandler = async { try const response = await importer await catche // handle a failed upload } const uploadYourData = { // logic here to upload the clean data your server}
Promise Overrides
Flatfile includes a basic native compatible Promise shim for IE support. You can override this with your preferred library by using the following global setting:
FlatfileImporterPromise = BluebirdPromise