You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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:

  • SimpleForm wraps the standard HTML form element, and uses the formProps prop to forward any extra attributes you need to the form itself.
  • When using FileInput, setting enctype="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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:04:07