【发布时间】:2012-06-26 11:25:03
【问题描述】:
我的 Blobstore 中存储了 Blob,并希望将这些文件推送到 Google 云端硬盘。 当我使用 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());
}
问题:当文件超过5mb时,超过了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();
此解决方案的问题: Google App Engine 不支持 FileOutputStream 来管理从 Blobstore 读取的 byte[]。
有什么想法吗?
【问题讨论】:
标签: java google-app-engine blobstore google-drive-api