如何在admin-on-rest的SimpleForm中传递enctype属性?
Fixing enctype="multipart/form-data" for File Uploads in admin-on-rest's SimpleForm
Hey there! I’ve dealt with this exact scenario when working with admin-on-rest’s file uploads, so let me share the solution that worked for me.
The key thing to know is that SimpleForm doesn’t accept the enctype prop directly. Instead, you need to pass it through the formProps attribute, which lets you pass additional props to the underlying HTML <form> element.
Here’s how to adjust your code:
<Create {...props}> <SimpleForm formProps={{ enctype: "multipart/form-data" }}> <FileInput source="files" label="Related files" multiple accept="text/*,image/*"> <FileField source="src" title="title" /> </FileInput> {/* Add other form fields here as needed */} </SimpleForm> </Create>
Why this works:
SimpleFormwraps the standard HTML form element, and uses theformPropsprop to forward any extra attributes you need to the form itself.- When using
FileInput, settingenctype="multipart/form-data"is mandatory for the browser to properly encode and send the file data to your backend.
This should get your file upload functionality working as expected!
内容的提问来源于stack exchange,提问作者Pratik Shah
相关产品推荐
相关产品推荐

