I am trying to create a file in Drive via REST (no SDKs), following the official APIs: https://developers.google.com/drive/v3/reference/files/create
So I follow two steps:
- Create file metadata (name, etc)
- Upload file content
Step 2 works like a charm, however I face some issues with step 1. Mime type is set fine, but as for the name I always get "Untitled" files, no matter of the actual name or type.
First I tried this:
POST https://www.googleapis.com/upload/drive/v3/files
Authorization: Bearer <OAuth 2.0 access token here>
Content-Type: image/png
{
"name": "test123.png"
}
Works partially - the file is created, content type is set correctly (e.g. after I write the data in step 2, I can actually preview it in Drive), but the name is "Untitled".
Then I looked again in the docu, and found the following: " Metadata URI, for metadata-only requests: POST https://www.googleapis.com/drive/v3/files " --> this returns 404 (not found).
After this I have tried the API in the API Explorer: https://developers.google.com/drive/v3/reference/files/create#try-it and noticed, that the call is actually against another URI (the file is successfully created and named as expected):
POST https://content.googleapis.com/drive/v3/files
Content-Type: application/json
{
"name": "test123.png"
}
When I try this in my code, I get 400 Bad Request. Of course I am adding also the bearer token authentication.
I feel I am missing something... can anyone help?