Javascript 如何在表单数据对象JS、Vue中指定excel文件的内容类型?

Javascript 如何在表单数据对象JS、Vue中指定excel文件的内容类型?,javascript,ajax,file,multipartform-data,content-type,Javascript,Ajax,File,Multipartform Data,Content Type,我创建FormData对象的方法 function createFormData (file, payload) { let formData = new window.FormData() formData.append('Excel', file) formData.append('SomeOtherKey', JSON.stringify(payload)) return formData } 我向服务器发送数据的方法 function sendDataToServer

我创建FormData对象的方法

function createFormData (file, payload) {
  let formData = new window.FormData()
  formData.append('Excel', file)
  formData.append('SomeOtherKey', JSON.stringify(payload))
  return formData
}
我向服务器发送数据的方法

function sendDataToServer (payload) {
  axios.post('/some-url', payload)
}
在请求体中,它设置为
application/octet-stream
,但我需要:
application/vnd.openxmlformats of icedocument.spreadsheetml.sheet

带有请求有效负载的屏幕


如何为文件指定正确的
内容类型

此帖子是否包含您要查找的内容?不幸的是,没有。有使用applicationin/json类型的,但在我的情况下,多部分/表单数据您能不能不只是将
内容类型
更新为
应用程序/vnd.openxmlformats of icedocument.spreadsheetml.sheet
?在
表单数据
对象中,我只能指定键、文件对象(从文件输入接收)和完整文件名。浏览器根据文件扩展自动设置内容类型找到答案: