Blobstoreにblobを保存していて、これらのファイルをGoogleドライブにプッシュしたいと考えています。GoogleAppEngineを使用する場合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());
}
問題:ファイルが5 mbを超えると、UrlFetchServiceリクエストサイズの制限を超えます(リンク:https ://developers.google.com/appengine/docs/java/urlfetch/overview#Quotas_and_Limits )
別の方法: Google Drive APIを使用して、次のコードを使用します。
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();
このソリューションの問題: FileOutputStreamは、Blobstoreから読み取られたbyte[]を管理するためのGoogleAppEngineではサポートされていません。
何か案は?