Can someone guide me on how to load and parse csv file in remix? I had tried doing it using Papaparser (below is my implementation), but it doesn't work. What I want in my application is that, upon selecting a csv file from the local storage and clicking the submit button, I shall get an array of objects which I can further process.
It will be very helpful if someone can help me resolve this, thank you!
import { db } from '~/utils/db.server'
import React, { useState } from "react";
import Papa from "papaparse";
import {createTaskFromTaskRequest} from "~/routes/create/create-task.server";
import {parseMultipartFormData} from "@remix-run/node/parseMultipartFormData";
import {UploadHandler} from "@remix-run/node/formData";
const uploadHandler: UploadHandler = async ({ name, stream, filename }) => {
await Papa.parse(filename, {
complete: function(results) {
console.log("Finished:", results);
return results
}
});
};
export const action: ActionFunction = async ({ request }) => {
console.log("im at the action");
const body = await parseMultipartFormData(request, uploadHandler);
console.log("body", body);
};
export default function FirstPage(){
return (
<Form method="post" action="/?index" encType="multipart/form-data">
<ul>
<input name="documents" type="file"/>
<button type="submit">Submit</button>
</ul>
</Form>
);
} ```