我对文件上传完全陌生......我正在使用 angular-file-upload它创建一个 XHR 外部 AngularJS 将文件上传到谷歌云存储。当我尝试上传时,我不断收到以下错误。我该如何解决这个问题?
400 Bad content type. Please use multipart.
这是我的 Controller 设置:
var uploader = $scope.uploader = new FileUploader({
url: 'https://www.googleapis.com/upload/storage/v1/b/bucketsbuckets/o?uploadType=multipart',
headers : {
'Authorization': 'Bearer ya29.lgHmbYk-5FgxRElKafV4qdyWsdMjBFoO97S75p4vB0G0d6fryD5LASpf3JUY8Av9Yzhp9cQP8IQqhA',
'Content-Type': 'multipart/form-data'
},
autoUpload:true
});
最佳答案
对于那些使用 fetch
的用户,只需删除 header 上的 content-type
即可。
我在github上发现了这个问题我引用:
Setting the Content-Type header manually means it's missing the boundary parameter. Remove that header and allow fetch to generate the full content type. It will look something like this:
Content-Type: multipart/form-data;boundary=----WebKitFormBoundaryyrV7KO0BoCBuDbTL
Fetch knows which content type header to create based on the FormData object passed in as > the request body content.
^^ 这对我有用。
关于javascript - 错误 : Bad content type. 请使用多部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30917332/