Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive API "watch"ing a folder, how to know what file was added

I have a test endpoint running and when I drop a file into the watched folder I get a request with the header X-Goog-Resource-State: update, but I don't seem to get an Id for the added file.

  • I get X-Goog-Resource-Id which I'd thought might be the new file, but I get a 404 if I try to get() it
  • I get X-Goog-Resource-Uri, but that belongs to the watched folder
  • I get an X-Goog-Channel-Id, but that clearly belongs to the channel not the file
  • And X-Request-Id, but that's just an opaque UUID

Am I required to fetch a complete list of files for the watched folder on every update and compare to a saved list? That doesn't feel right, but I'm at a loss.

Any guidance would be much appreciated.

like image 697
CJ Thompson Avatar asked Oct 21 '15 04:10

CJ Thompson


1 Answers

Is there any better way of doing this today? After searching the Drive API Docs it doesn't appear that it has changed.

I'll throw another idea out there if it has not changed. What I will probably end up doing is creating 2 folders, one for New Items and one for Processed Items. I'll watch the New Items folder and when notified, I'll process any files in the folder and move them to the Processed Items folder. Just personal preference on this one but I'd prefer not to change the files' properties or modify them in any way and I'd be a little paranoid that if I get them by time created I'd either process some files more than once or somehow one would get left out here or there.

It would be great to be able to receive notifications of added files including their IDs though!

like image 84
zpert Avatar answered Nov 02 '22 08:11

zpert