Skip to content
Discussion options

You must be logged in to vote

I can think of two good ways to get this done. I typically write an import script that starts up Payload with local: true, reads the CSV file and loops over the rows, mapping data to a data object and calls save on your collection(s). The other option is more work, but you can create a custom endpoint that handles the import from an uploaded file along with adding a custom component in Payload to the UI for users to submit data to.

Here is a limited example of what I've used for an import script:

import dotenv from 'dotenv';
import path from 'path';
import csv from 'csvtojson';
import payload from 'payload';
import { User } from '../payload-types';
import { UserSource } from './types'; //…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@opalepatrick
Comment options

Answer selected by zubricks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants