错误:错误的内容类型。请使用多部分 [英] error: Bad content type. Please use multipart

查看:160
本文介绍了错误:错误的内容类型。请使用多部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全不熟悉文件上传....我使用 angular-file-上传,然后在angularjs之外创建XHR ,以将文件上传到Google云端存储。当我尝试上传时,我不断收到下面的错误。我该如何解决这个问题?

  400不良内容类型。请使用多部分。 

这里是我的控制器设置:

  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
});


解决方案

问题是您使用的端点是用于分段上传,而不是基于FORM的分段上传。如果您将Content-Type设置为multipart / related而不是multipart / form-data,您应该可以继续操作。

端点www.googleapis.com/upload/storage/etc?uploadType=multipart,需要具有两部分的多部分消息,第一部分是JSON中对象的元数据,第二部分是数据。

有关这些要求的更多信息,请访问: https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload



如果但是,您希望以表单提交的方式进行上传,这也是可能的,但是规则是不同的。在这种情况下,您将使用各种适当的表单参数向storage.googleapis.com/BUCKET/OBJECT提交POST: https://cloud.google.com/storage/docs/reference-methods#postobject



现在,这一切都假设你正在尝试做一个上传作为多部分请求出于某种原因。如果你需要在对象上设置一些特定的元数据属性,这可能是必要的,但如果不是,你可能会让自己更难。一个简单的PUT到storage.googleapis.com/BUCKET/OBJECT将工作得很好(虽然我不熟悉角度文件上传,不知道它是否支持非表单式上传)。 p>

I'm totally new to file uploads....I'm using angular-file-upload which creates an XHR outside of angularjs to upload files to google cloud storage. When I try to upload I keep getting the error below. How can I resolve this?

400 Bad content type. Please use multipart.

Here's my controller setup:

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
  });

解决方案

The problem is that the endpoint you're using is for multipart uploads, but not FORM-based multipart uploads. If you set your Content-Type to "multipart/related" instead of "multipart/form-data", you should be able to proceed.

A multipart upload to that endpoint, "www.googleapis.com/upload/storage/etc?uploadType=multipart", expects a multipart message with exactly two parts, the first part being the metadata of the object, in JSON, and the second part being the data.

More on these requirements are here: https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload

If, however, you'd like to do an upload in the style of a form submission, that's also possible, but the rules are different. In this case, you'll submit a POST to "storage.googleapis.com/BUCKET/OBJECT" with a variety of appropriate form parameters: https://cloud.google.com/storage/docs/reference-methods#postobject

Now, this all assumes you're trying to do an upload as a multipart request for some reason. That might be necessary if you need to set some specific metadata properties on the object, but if not, you may be making things harder for yourself. A simple PUT to "storage.googleapis.com/BUCKET/OBJECT" will work just fine (although I'm not familiar with angular-file-upload and don't know whether it supports non-form-style uploads).

这篇关于错误:错误的内容类型。请使用多部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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