0

I have a simple command line tool that fetches preview images from a remote location and uploads to Filestack every time it runs, even if the images had been uploaded in previous runs. Is there a standard way I can check if a file already exists in Filestack before attempting an upload?

Options I'm considering:

One option would be to make HTTP HEAD request to the potential Filestack file URL, but AFAIK that's only possible if I have the Filestack image handle/key from the previous run.

The other option would be to :

  1. Store preview image id <> Filestack handle/key in a serializable map every time a new image is uploaded
  2. Serialize the map when the run is done
  3. At the beginning of the next run deserialize the map so I have an idea of was uploaded.

I just want to know if there's a better or Filestack(standard) way of doing this other than the options I'm considering.

  • 2
    store locally the IDs and before upload check in your local – hovanessyan Mar 22 '19 at 11:40
  • @hovanessyan Yeah, that's why I listed serialization/deserialization as an option I'm considering. What I want to confirm is, if there's a standard or better approach. – Kehinde Adedamola Shittu Mar 22 '19 at 12:03
  • if the service you're calling offers "isExisting by ID" functionality or something similar that would be the standard way. If the service is not offering that you will have to store locally. If you go with the serialization, consider protobuf or Thrift instead of default Java serialization. – hovanessyan Mar 22 '19 at 13:00

1 Answers1

0

Did a bit of research and it seems with Filestack there's no way to check if a file was uploaded unless the file handle/key is known as I stated earlier. So I settled for the second approach which is to store a key/value map of resourceId and file URL locally, then use object serialization and deserialization technique to preserve state and it works pretty well. here are the steps

  1. Add resourceId <> Filestack handle/key to a serializable map every time a new image is uploaded
  2. Serialize the map when the current run is done
  3. At the beginning of the next run deserialize the map so you have an idea of has already been uploaded.