0

The following StackOverflow question seems to be widely referenced on this subject.

How do I add/create/insert files to Google Drive through the API?

These simple directions failed for me. Here's what I send Google:

POST https://www.googleapis.com/upload/drive/v2/files
Authorization: Bearer ya29.AHES6ZRO8SLGjreb1DbNju62WF-AHES6ZRO8SLGjreb1DbNju62
Content-Length: 347
Content-Type: multipart/mixed; boundary="1366986113131560"

--1366986113131560
Content-Type: application/json

{"mimeType":"text/plain","title":"hi.txt","parents":[{"id":"0BxnfVWt9egI_VDJnbFBpZDExTmM"}]}
--1366986113131560
Content-Type: text/plain

setPendingSave
loadSegments
setSequence
addSegment
setspanformat
setspanformat
hidespanformat
setspanformat
setspanformat
hidespanformat
--1366986113131560--

When I submit this, Google responds with the error message:

Multipart content has too many non-media parts

I don't want belabor this point, but it would be nice to demonstrate that the API works without having to rely on Google libraries.

Community
  • 1
  • 1
Sunny Jim
  • 585
  • 5
  • 13
  • By accident, I tested again using the Mime-Type "image/jpeg" and the upload succeeded. Is "text/plain" not a valid file type? – Sunny Jim Apr 26 '13 at 15:23
  • Additionally, setting a "Content-Transfer-Encoding" value in a sub-part header results in the message "malformed multipart body". – Sunny Jim Apr 26 '13 at 15:56

1 Answers1

0

Please use https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart as your endpoint. If you don't include uploadType=multipart, we can extract metadata and content separately.

Burcu Dogan
  • 9,153
  • 4
  • 34
  • 34
  • Your statement is incorrect. See my first comment above: A file was successfully inserted by using a different, and incorrect, mime-type. – Sunny Jim Apr 26 '13 at 16:55
  • Metadata could be represented as `text/plain` at the infrastructure we (Google Drive) depend on uploads. It assumes that you're trying to upload metadata in two different formats which is illegal. That's why I'm suggesting you to separate the requests. – Burcu Dogan Apr 26 '13 at 22:33
  • I've just realized you're not using multipart upload type. Fixing my answer. – Burcu Dogan May 06 '13 at 13:44