WEB:提交文件+文本字段,使用单一表单还是单独的?
我目前正在开发一个简单的前端,它允许用户将数据输入到文本字段中,并在同一表单上上传文件。
我知道我必须使用 multipart/form-data 才能发送文件,但我很好奇发送文本数据的最佳方式是什么。我的选项是:
使用 multipart/form-data 以单个表单提交文件和文本数据
在两个不同端点之间分离文件和文本数据,允许我在发送之前将文本数据格式化为 JSON 客户端
我不认为这样做会非常困难,但我很好奇通常认为什么是这种情况下的最佳实践。
I'm currently working on a simple frontend that will allow users to input data into text fields and also upload files on the same form.
I know that I'll have to use multipart/form-data in order to send the files, but I'm curious as to what would be the best way to also send the text data. My options are:
Submit files and text data in a single form using multipart/form-data
Separate files and text data between two different endpoints, allowing me to format the text data to JSON client-side before sending it off
I don't think doing either would be terribly difficult, but I'm curious as to what is generally considered to be the best practice in this scenario.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您期望用户的工作流程。
如果您希望他们填写的字段与您上传的文件紧密相关,请在一张表单中完成所有这些操作。例如,如果上传的是图像,并且字段包含图像的标题,则它们会放在一起并且应采用单一表单。
如果从您的页面来看,只上传文件或只填写表单中的字段并提交它们是有意义的,请使用两个表单对象。
在进行一些可用性测试之前,您可能不会知道它的效果如何。您可能需要对其进行更改才能使一切顺利进行。
This depends on the workflow you expect of your users.
If the fields you want them to fill in are tightly bound to the file you upload, do them all in one form. For example, if it's an image being uploaded and the field contains the image's caption, they go together and should be in a single form.
If it makes sense from your page to just upload the file, or just fill out the fields in the form and submit them, use two form objects.
You probably won't know how well this works until you do some usability testing. You may have to change it up to get everything working smoothly.