1
votes

My final aim is to allow user to upload some content on to a google drive word document in their individual account.

I am using the PHP example provided on https://developers.google.com/drive/v2/reference/files/insert#examples. When uploading a simple text file, it works fine.

Then (after wasting almost 8 hours with mimetype application/msword. Not sure why the docs don't make it easier to find such common details.) I changed the mimetype to application/vnd.google-apps.document with empty data, and it worked absolutely fine.

Then, I created a doc file on google drive web interface and then exported it to my machine. It was saved as docx. Then in the example, this file is used as the source for data, I keep getting Error calling POST https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart: (400) Bad Request error.

The error message does not even provide any more details as to what is wrong with the request.

[responseBody:protected] => {
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "badRequest",
        "message": "Bad Request"
      }
    ],
    "code": 400,
    "message": "Bad Request"
  }
}
1
Are you wanting to create a Google Document or a binary MSWord file? What happens when you leave the mime type out?Ali Afshar
The user has simple formatted text (javascript wsgi editor) stored in database. The user should be able to create an empty google doc or a new google doc with this formatted text in it.MavWolverine
UPDATE: if i leave the mimetype out, the code works fine. But then I am unable to edit the file as well. No preview available This item was created with My App Test, a Google Drive app. Download this file or use one of the apps you have installed to open it.MavWolverine
Hi Ali, any suggestions?MavWolverine
Still no luck with this. I believe since docs is the major aim of gdrive, creating new word docs with content using the API should be a working and documented feature.MavWolverine

1 Answers

0
votes

You probably have to put the Word file's content as a string into the $request['content']

If it's .DOCX the proper MIME-type is a:

application/vnd.openxmlformats-officedocument.wordprocessingml.document

Reference: MSDN Library

Well, how shall one tell what's wrong by the response, but not the request which produces it?

You probably could have just written "HTTP400 - the crap is not working" instead,

which would provide about an equal amount of information.

HTTP Response-Code #400 in general means,

That the HTTP request was malformed (e.g. is missing parameters, wasn't properly escaped, etc).

^ ...and this is certainly the correct answer - according to the sample response.

And this is exactly the reason why the information provided isn't sufficient to provide you with a straight answer. I'd also wish the API to have a little more details in the responses (especially on occasional file validation errors) - because sometimes one can only guess what's wrong "on the other side".

Best practice is to start from a very simple working version and add some complexity then.

If you'd wish to have the issue reviewed/resolved, you should add a sample request.

Doesn't even matter how the code looks like - when the request is obviously malformed.

Ordinary I offer web-scripting as a service, just currently kinda out-of-resources.