I have blobs stored in my Blobstore and want to push these files to the Google Drive. When I use the Google App Engine UrlFetchService
URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
URL url = new URL("https://www.googleapis.com/upload/drive/v1/files");
HTTPRequest httpRequest = new HTTPRequest(url, HTTPMethod.POST);
httpRequest.addHeader(new HTTPHeader("Content-Type", contentType));
httpRequest.addHeader(new HTTPHeader("Authorization", "OAuth " + accessToken));
httpRequest.setPayload(buffer.array());
Future<HTTPResponse> future = fetcher.fetchAsync(httpRequest);
try {
HTTPResponse response = (HTTPResponse) future.get();
} catch (Exception e) {
log.warning(e.getMessage());
}
Problem: When the file exceeds 5 mb, it exceeds the limit of the UrlFetchService request size (Link: https://developers.google.com/appengine/docs/java/urlfetch/overview#Quotas_and_Limits)
Alternative: Using the Google Drive API I have this code:
File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);
// File's content.
java.io.File fileContent = new java.io.File(filename);
FileContent mediaContent = new FileContent(mimeType, fileContent);
File file = service.files().insert(body, mediaContent).execute();
Problem with this solution: FileOutputStream is not supported on Google App Engine to manage byte[] read from Blobstore.
Any ideas?