androidgoogle-drive-apiretrofit2google-drive-android-apigoogle-drive-shared-drive

Google Drive Api v3 upload to sharedDrive not working even with supportsAllDrives=true


I am trying to upload an image to a folder in Shared Drive. I managed to do that on My Drive but when I am trying to achieve this to the Shared Drive I get the following error:

{
  "error": {
    "code": 404, 
    "message": "File not found: 1ZQuuXVDx3I5rs6OnH8WvbWfo6HplnfW8.", 
    "errors": [
      {
        "locationType": "parameter", 
        "domain": "global", 
        "message": "File not found: 1ZQuuXVDx3I5rs6OnH8WvbWfo6HplnfW8.", 
        "reason": "notFound", 
        "location": "fileId"
      }
    ]
  }
}

This drives me nuts right now because I've read the documentation many times and I cannot find the solution. I have tried on the Android with Retrofit, on Postman and even on OAuth2 Playground that is provided by Google.

The request is this one, copy pasted from the OAuth2 Playground:

POST /upload/drive/v3/files?uploadType=multipart HTTP/1.1
Host: www.googleapis.com
Content-length: 50295
Content-type: multipart/related; boundary="===============323232404548=="
Authorization: Bearer ya29.a0AfH6SMBHmEo0Q9-8dXhhCY7wGrTj9PsFTCd0YUdLtyGJSfdO
--===============323232404548==
Content-type: application/json

{
   "supportsAllDrives": true,
   "driveId":"0APRAdsf3Sdfsk9PVA",
   "name":"test.jpeg",
   "parents":[
      "1ZQuuXVDx3I5rs6OnH8WvbWfo6HplnfW8"
   ]
}
--===============323232404548==
Content-type: image/jpeg

What exactly is the problem? I have tried also using the driveId and the supportsAllDrives to the header of the request.

Any help is really appreciated. Links that I followed:

https://developers.google.com/drive/api/v3/manage-uploads#multipart and https://developers.google.com/drive/api/v3/reference/files/create


Solution

  • As indicated in the document, supportsAllDrives is a query parameter. Which means that it should be included in the URI and not in the request body.

    From:

    https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart
    

    To:

    https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&supportsAllDrives=true
    

    If supportsAllDrives is not included in the query parameters, the default value would be false. This causes your response to have "File not found" message since it wasn't able to find or access the shared drive.