使用Google Drive Rest API的有效负载传递元数据

时间:2015-11-05 06:47:03

标签: ruby rest google-drive-api rubygems rest-client

我使用google drive api

在使用Payload传递元数据时遇到了问题

我一直在尝试以下操作,但标题,说明等不适用于驱动器上的上传文件。

  upload_url = "https://www.googleapis.com/upload/drive/v2/files"
  access_token = "---secret_access_token---"

  fileitem = File.open('<filename>.pptx')
  fileinfo = {"title": "insertedFromApi.pptx", "description": "Test description of file being uploaded from the API"}
  params = {convert: true}
  response = RestClient::Request.execute(
      :method => :post,
      :url => upload_url,
      :headers => {"params": params, "uploadType": "multipart", content_type: 'multipart/related', accept: 'application/json', 'Authorization': "Bearer " + access_token},
      :payload => {:content => fileitem, metadata: {title: 'insertedfromapi.pptx'}}
  )

虽然谷歌api表示他们只接受多部分请求中的元数据,但我一直这样做,所有推送的文件仍然是UNTITLED

示例请求given here: -

POST /upload/drive/v2/files?uploadType=multipart HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer your_auth_token
Content-Type: multipart/related; boundary="foo_bar_baz"
Content-Length: number_of_bytes_in_entire_request_body

--foo_bar_baz
Content-Type: application/json; charset=UTF-8

{
  "title": "My File"
}

--foo_bar_baz
Content-Type: image/jpeg

JPEG data
--foo_bar_baz--

0 个答案:

没有答案