我正在使用Google Drive API Java客户端库将文件插入Google云端硬盘。上传到云端硬盘的任何文件都会在上传时修改时间,而不是原始文件修改时间。我已使用setModifiedDate
File
对象来设置日期。
在Google Developers看到文档时,我看到以下文字 -
上次此文件被任何人修改(格式化RFC 3339 时间戳)。这只有在setModifiedDate更新时才可变 参数已设置。
但是,我在文档中找不到参数setModifiedDate
,并且Java库在类setSetModifiedDate(Boolean arg)
中都没有方法com.google.api.services.drive.Drive.Files.Insert
(相反,更新类{{ 1}}包含完美运行的com.google.api.services.drive.Drive.Files.Update
方法。
答案 0 :(得分:1)
此代码适用于我保留修改日期&我将文件上传到云端硬盘之前的文件时间。
long modifiedDateTime = new java.io.File("/path/to/file").lastModified();
Time t = new Time();
t.set(modifiedDateTime);
t.switchTimezone(Time.getCurrentTimezone());
String modifiedDateAsRfc3339 = t.format3339(false);
// create the file to upload here
com.google.api.services.drive.model.File body = new File();
body.setTitle("/path/to/file");
body.setMimeType("mimetype");
// here is where you set the modified date to match the file's modified date
body.setModifiedDate(com.google.api.client.util.DateTime.parseRfc3339(modifiedDateAsRfc3339));
InputStreamContent mediaContent;
......