【发布时间】:2017-06-01 10:06:00
【问题描述】:
我仍在努力解决它。
我可以让用户通过文件输入选择文件(甚至多个):
<form>
<div>
<label>Select file to upload</label>
<input type="file">
</div>
<button type="submit">Convert</button>
</form>
我可以使用<fill in your event handler here> 捕获submit 事件。但是一旦我这样做了,如何使用fetch 发送文件?
fetch('/files', {
method: 'post',
// what goes here? What is the "body" for this? content-type header?
}).then(/* whatever */);
【问题讨论】:
-
官方文档在尝试一些答案失败后对我有用:developer.mozilla.org/en-US/docs/Web/API/Fetch_API/…,可以确认:1.需要在FromData中包装文件; 2.不需要在请求头中声明
Content-Type: multipart/form-data
标签: javascript fetch-api