【发布时间】:2017-06-11 17:12:33
【问题描述】:
我正在使用 google drive V3 REST api 从 POST 请求上传多部分文件,下面是 java 代码
String accessToken = "xyz";
Credential credential = new GoogleCredential().setAccessToken(accessToken);
Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName("xyz")
.build();
File fileMeta = new File();
fileMeta.setName(fileName);
fileMeta.setMimeType("application/vnd.google-apps.file");
if (!parentFolderId.isEmpty()) {
fileMeta.setParents(Collections.singletonList(parentFolderId));
}
//Code to upload file in GDrive
java.io.File tmpFile = java.io.File.createTempFile("uploadFile", ".tmp");
//Writing the file content to the new file
InputStream in = multipartFile.getInputStream();
FileOutputStream fos = new FileOutputStream(tmpFile);
IOUtils.copy(in, fos);
in.close();
fos.close();
tmpFile.deleteOnExit();
FileContent mediaContent = new FileContent(null, tmpFile);
File file = service.files().create(fileMeta, mediaContent)
.setFields("id")
.execute();
上传工作正常,但所有上传都自动转换为我不想要的文档。我从问题Google Drive: Automatically convert files on upload? 中看到,在插入期间需要设置convert=true。但此选项在 V3 中不可用。
谁能告诉我如何在上传期间禁用此自动转换?
【问题讨论】:
标签: java file-upload google-drive-api file-conversion