Nek
Nek

Reputation: 493

Keep modified time of file upon insert into Google Drive API on Android

I am inserting files into Google Drive through the API on Android. Any file that is uploaded takes on the modified time of when it as uploaded, not the original file modified time. If I upload something through the Google Drive App on my desktop, the original modified time of the file is kept.

I have tried using the setModifiedDate() method in the File object, but it doesn't seem to work OR i'm sending the wrong date format possibly? I have tried both of these formats:

2012-08-09T05:34:36-07:00
2012-08-09T05:34:36-0700

Neither seemed to work. Is there an easier way to have it retain the original modified time of the file without having to set it manually (which I can't get to work anyhow)?

The code i am using is the same as the example here: https://developers.google.com/drive/v2/reference/files/insert

Thanks

Upvotes: 3

Views: 1567

Answers (2)

Nek
Nek

Reputation: 493

I'll answer my own question here.

It turns out I just needed to use setModifiedDate() (which I was already doing) but I needed to NOT set a description using setDescription(). I am not sure if there is a limitation or a bug, but as soon as I removed the description I was setting, then the date I was setting with setModifiedDate() started to work.

I also confirmed the same behaviour with the API Explorer here: https://developers.google.com/drive/v2/reference/files/insert

Upvotes: 2

Ali Afshar
Ali Afshar

Reputation: 41633

You need to do both. The setModifiedDate query parameter to update implies that the modifiedDate field that you pass will be used as the modified date for that file. So in short, you need to do both.

This is really useful for synchronizing use-cases.

Upvotes: 0

Related Questions