2

我正在使用 Google Drive API Java 客户端库将文件插入到 Google Drive。上传到云端硬盘的任何文件都采用上传时的修改时间,而不是原始文件的修改时间。我已经使用setModifiedDateofFile对象来设置日期。

在查看Google Developers的文档时,我看到以下文本 -

上次此文件被任何人修改的时间(格式化的 RFC 3339 时间戳)。当设置了 setModifiedDate 参数时,这仅在更新时是可变的。

但是,我在文档中找不到参数setModifiedDate,Java 库也没有setSetModifiedDate(Boolean arg)类中的方法com.google.api.services.drive.Drive.Files.Insert(相反,更新类com.google.api.services.drive.Drive.Files.Update包含setSetModifiedDate(Boolean arg)完美工作的方法)。

4

1 回答 1

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;
......
于 2013-06-28T16:36:44.267 回答