Replies: 2 comments 1 reply
-
Here's a sample: https://stackblitz.com/edit/remix-run-remix-shx966?file=app%2Froutes%2F_index.tsx export async function action({ request }: ActionArgs) {
const uploadHandler = unstable_createMemoryUploadHandler({
maxPartSize: 500_000,
});
const formData = await unstable_parseMultipartFormData(
request,
uploadHandler
);
// Remix sets files in FormData as a File object
const file = formData.get('file') as File;
// Convert the file to a Blob
const blob = new Blob([file]);
// Get the contents as an ArrayBuffer
const data = await blob.arrayBuffer();
// Do what you want with the data
// Like convert to base64
const base64 = Buffer.from(data).toString('base64');
// Or just a plain text string
const text = Buffer.from(data).toString();
return json({ name: file.name, size: file.size, base64, text });
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
Thank you very much. I've used your example and got everything working. Thank you again. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I've tried everything and I am going crazy. I cannot get the binary content of an uploaded file. This is my action code:
This code prints:
You can see also the commented code as I've tried to create my own upload handler. Not working. I've tried to use the Remix memory handler. Not working. Please, tell me what am I doing wrong?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions