0

I am using Google drive rest API to perform upload/download operations on android, but there is no clear API documentation for resumable operations on the google doc. I have successfully get the access token for drive operations. Even I cannot add google drive rest API tag. Any help would be appreciated.

I have successfully get the access token for drive operations. Any help would be appreciated.

        try {
            URL url;
            url = new URL("https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable");
            HttpURLConnection request;
            request = (HttpURLConnection) url.openConnection();
            request.setRequestMethod("POST");
            request.setDoInput(true);
            request.setDoOutput(true);
            request.setRequestProperty("Authorization", "Bearer " + credential.getToken());
            request.setRequestProperty("X-Upload-Content-Type", getMimeType(file.getPath()));
            request.setRequestProperty("X-Upload-Content-Length", String.format(Locale.ENGLISH, "%d", file.length()));
            request.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
            String body = "{\"name\": \"" + file.getName() + "\", \"parents\": [\"" + "parentId12345678" + "\"]}";
            request.setRequestProperty("Content-Length", String.format(Locale.ENGLISH, "%d", body.getBytes().length));
            OutputStream outputStream ;
            outputStream = request.getOutputStream();
            outputStream.write(body.getBytes());
            outputStream.close();
            request.connect();
        } catch (Exception e) {
            e.printStackTrace();
        }


Tanveer Munir
  • 1,956
  • 1
  • 12
  • 27
Reva
  • 59
  • 1
  • 1
  • 7
  • Have you look at these answer [url1](https://stackoverflow.com/questions/25288849/resumable-uploads-google-drive-sdk-for-android-or-java), [url2](https://stackoverflow.com/questions/24455422/android-resumable-upload-to-google-drive) – Tanveer Munir Feb 11 '19 at 11:05

1 Answers1

0

Reading the Google drive rest API doc setting the

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

will do the job

from the doc:

The following example shows how to initiate a resumable session to

POST https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable HTTP/1.1
Authorization: Bearer [YOUR_AUTH_TOKEN]
Content-Length: 38
Content-Type: application/json; charset=UTF-8
X-Upload-Content-Type: image/jpeg
X-Upload-Content-Length: 2000000

{
  "name": "myObject"
}
Erik
  • 5,039
  • 10
  • 63
  • 119