is there a way to delete an object from storage with less than 3 requests to the storage provider?

Skip to first unread message

Gavriel Fleischer

Oct 19, 2015, 3:06:40 AM10/19/15
to ruby-fog

I started using fog storage for a project. I do the most simple actions: upload an object, get the object, delete the object. My code looks something like this:

storage = get_storage(...) // S3 / OpenStack / ...
dir = storage.directories.get(bucket)
if !dir.nil?
  dir.files.create(key: key, body: body)

  # or:

  file = dir.files.get(key)
  if !file.nil?

In all cases there's a 1st step to get the directory, which does a request to the storage engine.
Then there's another step to do whatever I'd like to do (in case of delete there's even a 3rd step).

However if I look at let's say the Amazon S3 api, it's clear that deleting an object doesn't need 3 requests to amazon.

Is there a way to use fog but make it do less requests to the storage provider?

Benjamin Manns

Oct 19, 2015, 7:44:19 AM10/19/15
Hi Gavriel,

Generally Fog::Foo::Bar#get will issue a GET request to your storage provider that will verify that the file or directory exists and fetch metadata about it. If you want to skip that step, you can usually use new(key: key) instead of get(key).

In your example:

dir = bucket)
file = key)

would issue a single DELETE request against bucket/key. The request may raise an exception if the file or bucket does not exist.


You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Reply all
Reply to author
0 new messages