1
votes

I am trying to upload a file using the Google Drive resumable upload api[https://developers.google.com/drive/web/manage-uploads#resumable] and i'm always getting a 400 status code with Invalid Upload request in the step 3 of the process.

For the step 1(Starting a resumable session), I get the session uri and it's when I upload the contents I'm getting a bad request error.

REQUEST HEADERS:
{
  "X-Upload-Content-Length": 249159,
  "X-Upload-Content-Type": "application/pdf",
  "content-type": "application/json",
  "Authorization": "Bearer ya..."
}

REQUEST BODY:
{
  "parents": [
    {
      "id": "0B..."
    }
  ],
  "title": "New file.pdf"
}

And i got the response back with the session uri as https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable&upload_id=AEnB2UpNCcQgsbuqKer6z25jVRX4ijweQkpAJ1aQ1nEQPGi_ODtvob9vSwQk2oyjzyUNQs-b2HenMst92HQo6WMKmQyO1lgTww

For the step 3(Uploading the file) Here are the request headers.

{
  "Content-Length": 249159,
  "Accept-Encoding": "gzip, deflate",
  "Accept": "*/*",
  "User-Agent": "python-requests/2.3.0 CPython/2.7.8 Darwin/14.0.0",
  "Content-Range": "bytes 0-249159/249159",
  "Content-Type": "application/pdf",
  "Authorization": "Bearer ya..."
}

And the request body contains the data who's length is again the same. The data is a chunk obtained from another url using python requests module.

The following is the response for the above request from google

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "badRequest",
        "message": "Invalid Upload Request"
      }
    ],
    "code": 400,
    "message": "Invalid Upload Request"
  }
}

It works with other clouds(the same method) except for Google Drive. What am I missing here?

1

1 Answers

2
votes

I finally nailed it myself. It was a bug in the code where the content-range for the last chunk was off by 1 byte.