Java 如何将大文件(>;5 mb)从Blobstore发布到Google Drive?

Java 如何将大文件(>;5 mb)从Blobstore发布到Google Drive?,java,google-app-engine,blobstore,google-drive-api,Java,Google App Engine,Blobstore,Google Drive Api,我的Blobstore中存储了Blob,希望将这些文件推送到Google驱动器。 当我使用谷歌应用程序引擎服务时 URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService(); URL url = new URL("https://www.googleapis.com/upload/drive/v1/files"); HTTPRequest httpRequest = new HTTPRequest(url, HTTP

我的Blobstore中存储了Blob,希望将这些文件推送到Google驱动器。 当我使用谷歌应用程序引擎服务时

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());
}
此解决方案的问题:Google App Engine不支持FileOutputStream来管理从Blobstore读取的字节[]


有什么想法吗?

要做到这一点,请使用块小于5兆字节的可恢复上传。这在Google API Java客户端for Drive中很容易做到。下面是根据您已经提供的驱动器代码改编的代码示例

File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);

java.io.File fileContent = new java.io.File(filename);
FileContent mediaContent = new FileContent(mimeType, fileContent);

Drive.Files.Insert insert = drive.files().insert(body, mediaContent);
insert.getMediaHttpUploader().setChunkSize(1024 * 1024);
File file = insert.execute();
有关更多信息,请参阅相关类的javadocs:


感谢您调整我的驱动器代码。我通过利用可恢复上传更新我的应用程序。将此代码上传到Google应用程序引擎后,我得到java.lang.NoSuchMethodError:com.Google.api.services.drive.drive$Files$Insert.getMediaHttpUploader()Lcom/Google/api/client/googleapis/MediaHttpUploader;我需要在这方面做更多的研究…你有哪个版本的google api java客户端?这是最新的吗?看这里:谢谢,维克!更新所有使用过的API库后,您提供的代码工作得非常好!
File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);

java.io.File fileContent = new java.io.File(filename);
FileContent mediaContent = new FileContent(mimeType, fileContent);

Drive.Files.Insert insert = drive.files().insert(body, mediaContent);
insert.getMediaHttpUploader().setChunkSize(1024 * 1024);
File file = insert.execute();