I am following the remix guide on how to upload files from a form. https://remix.run/docs/en/main/utils/unstable-create-file-upload-handler.
In my action I have a file uploader that looks like so,
const uploadHandler = unstable_composeUploadHandlers(
unstable_createFileUploadHandler({
// Limit file upload to csv file
filter: ({ contentType }) => contentType.includes('text/csv'),
// Store the email files in the correct folder
directory: './public/files',
// By default, `unstable_createFileUploadHandler` adds a number to the file
// names if there's another with the same name; by disabling it, we replace
// the old file
avoidFileConflicts: false,
// Use the actual filename as the final filename
file: ({ filename }) => filename,
}),
unstable_createMemoryUploadHandler(),
);
const formData = await unstable_parseMultipartFormData(request, uploadHandler);
const file = formData.get('file')
const userField = formData.get('user_field');
console.log(userField);
console.log(file);
When I console log my values userField
look correct but file
is a type Blob { size: 0, type: 'application/octet-stream' }
. However, when I remove unstable_createMemoryUploadHandler
from the upload handler it correctly returns a type of NodeOnDiskFile
but then userField
is null. What am I doing wrong? Thanks.