CSV Export & Import
5 min read
Exporting and Importing Contacts
Exporting and Importing Contacts
Everything you’ve built so far either renders HTML or redirects the
browser after a form submission. A CSV download is neither — it needs to
return a file with specific headers telling the browser to save it rather
than display it. That’s a job for a Route Handler, not a Server
Action.
Importing, on the other hand, fits the Server Action pattern you already
know: a form uploads a file, a Server Action reads it and inserts rows.
The only new piece is a small hand-written CSV parser, since this project
doesn’t pull in an external library for something this contained.