从HTML表单发布blob的表单输入类型是什么? [英] What is the form input type for posting blob from an HTML Form?

查看:222
本文介绍了从HTML表单发布blob的表单输入类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将录制的视频(保存为blob)包含在将要发布的表单中。

I want to include a recorded video (saved as a blob) to a form that will be posted.

两个问题:


  1. 发布blob所需的输入类型是什么?

  2. 如何将blob分配给该输入类型?

我见过的一些建议使用输入类型的文件。

Some of what I've seen suggested using a input type of file.

示例表单:

<form method="POST>  
    <input type="text" class="hidden" name="filename"/>
    <input type="<UNKNOWN>" class="hidden" name="filedata"/>
    <input type="submit" />
</form>

我假设我会做类似的事情

I'm assuming I'd do something like

$("[name=filename]").val(myBlob)


推荐答案

我认为唯一的方法是使用FormData()对象将Blob附加到表单。

I think the only way to attach a blob to a form is with a FormData() object.

var formData = new FormData();
formData.append("name", blob, filename);

然后使用XMLHttpRequest发送表单喜欢:

and then sending the form using an XMLHttpRequest like:

var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.send(formData);

所以如果你需要将这个blob一起发送您可以使用其他表格信息而是将普通表单数据附加到FormData对象并发送整个内容。或者想出一些其他解决方案,比如只发送blob并让服务器返回与上传相关联的密钥,然后将其插入到表单的隐藏元素中,因此当表单正常提交时,您的服务器可以附加该数据以前上传的blob。

So if you need to send this blob together with other form information you could instead attach the normal form data to your FormData object and send the whole thing. Or perhaps come up with some other solution like sending only the blob and have the server return a key associated to the upload which you then insert into a hidden element of your form, so when the the form is submitted normally your server can attach that data to the previously uploaded blob.

这篇关于从HTML表单发布blob的表单输入类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆