Google app engine 将com.google.api.services.drive.model.File转换为java.io.File
因此,我想创建一个Google app engine 将com.google.api.services.drive.model.File转换为java.io.File,google-app-engine,google-drive-api,java-io,multipartentity,Google App Engine,Google Drive Api,Java Io,Multipartentity,因此,我想创建一个java.io.File,以便使用它生成一个多部分表单POST请求。我有一个com.google.api.services.drive.model.file格式的文件,所以我想知道,有没有办法将这个google文件转换成Java文件?这是一个使用Google app Engine SDK的web应用程序,它禁止我尝试的所有方法不,你知道,你似乎无法从com.Google.api.services.drive.model.File转换为java.io.File。但仍然可以使用驱动
java.io.File
,以便使用它生成一个多部分表单POST请求。我有一个com.google.api.services.drive.model.file
格式的文件,所以我想知道,有没有办法将这个google文件转换成Java文件?这是一个使用Google app Engine SDK的web应用程序,它禁止我尝试的所有方法不,你知道,你似乎无法从com.Google.api.services.drive.model.File转换为java.io.File。但仍然可以使用驱动器中的数据生成多部分表单POST请求
因此,com.google.api.services.drive.model.File类用于存储有关文件的元数据。它没有存储文件内容
如果要将文件内容读入内存,驱动器文档中的这段代码片段将演示如何执行此操作。一旦文件进入内存,您就可以对其执行任何操作
/**
* Download the content of the given file.
*
* @param service Drive service to use for downloading.
* @param file File metadata object whose content to download.
* @return String representation of file content. String is returned here
* because this app is setup for text/plain files.
* @throws IOException Thrown if the request fails for whatever reason.
*/
private String downloadFileContent(Drive service, File file)
throws IOException {
GenericUrl url = new GenericUrl(file.getDownloadUrl());
HttpResponse response = service.getRequestFactory().buildGetRequest(url)
.execute();
try {
return new Scanner(response.getContent()).useDelimiter("\\A").next();
} catch (java.util.NoSuchElementException e) {
return "";
}
}
可能有助于从Google AppEngine发出多部分POST请求。不,您似乎无法从com.Google.api.services.drive.model.File转换为java.io.File。但仍然可以使用驱动器中的数据生成多部分表单POST请求 因此,com.google.api.services.drive.model.File类用于存储有关文件的元数据。它没有存储文件内容 如果要将文件内容读入内存,驱动器文档中的这段代码片段将演示如何执行此操作。一旦文件进入内存,您就可以对其执行任何操作
/**
* Download the content of the given file.
*
* @param service Drive service to use for downloading.
* @param file File metadata object whose content to download.
* @return String representation of file content. String is returned here
* because this app is setup for text/plain files.
* @throws IOException Thrown if the request fails for whatever reason.
*/
private String downloadFileContent(Drive service, File file)
throws IOException {
GenericUrl url = new GenericUrl(file.getDownloadUrl());
HttpResponse response = service.getRequestFactory().buildGetRequest(url)
.execute();
try {
return new Scanner(response.getContent()).useDelimiter("\\A").next();
} catch (java.util.NoSuchElementException e) {
return "";
}
}
可能有助于从Google AppEngine发出多部分POST请求。在GoogleDrive Api v3中,您可以将文件内容下载到OutputStream中。您需要文件id,您可以从com.google.api.services.drive.model.file获得该id:
在GoogleDrive Api v3中,您可以将文件内容下载到OutputStream中。您需要文件id,您可以从com.google.api.services.drive.model.file获得该id:
对,上面的代码基本上就是我用来获取原始字符串文件数据的代码。但我不知道如何以GAE允许的方式使用该字符串重新创建java.io.File对象,我需要一个java.io.File对象来创建一个FileBody对象,它将附加到多部分表单post。检查您发布的其他堆栈溢出链接其他链接依赖于存储在GAE数据库中的文件。你认为这是让整个过程正常运行的唯一方法吗?它不完全是复制/粘贴解决方案。您在Google drive中存储了一个文件,并且希望通过多部分POST请求发送该文件。GAE文档显示了如何从Google Drive读取文件,堆栈溢出示例显示了如何发送多部分POST请求。把这两件事放在一起编辑,你就有了解决办法。您可能需要更改一些内容。对,上面的代码基本上就是我用来获取原始字符串文件数据的代码。但我不知道如何以GAE允许的方式使用该字符串重新创建java.io.File对象,我需要一个java.io.File对象来创建一个FileBody对象,它将附加到多部分表单post。检查您发布的其他堆栈溢出链接其他链接依赖于存储在GAE数据库中的文件。你认为这是让整个过程正常运行的唯一方法吗?它不完全是复制/粘贴解决方案。您在Google drive中存储了一个文件,并且希望通过多部分POST请求发送该文件。GAE文档显示了如何从Google Drive读取文件,堆栈溢出示例显示了如何发送多部分POST请求。把这两件事放在一起编辑,你就有了解决办法。你可能需要改变一些事情。