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();
}