markevans / dragonfly

A Ruby gem for on-the-fly processing - suitable for image uploading in Rails, Sinatra and much more!
http://markevans.github.io/dragonfly
MIT License
2.12k stars 244 forks source link

Requesting filename without download file for custom stores #485

Closed alagos closed 6 years ago

alagos commented 6 years ago

I'm developing a custom store for azure and so far is working, but I'm having a perfomance issue. My .read method is like this one:

    def read(uid)
      path = full_path(uid)
      result, body = storage.get_blob(container_name, path)
      meta = result.metadata
      [body, meta]
    rescue Azure::Core::Http::HTTPError
      nil
    end

This is returning the meta and the data as it is described in the docs. The bad thing is that the .get_blob method downloads the complete file when I just need the file name contained in the meta. Imagine the scenario of a message with many attachments and I just want to display the filenames for each of those attachments, currently is downloading each of the files without needing it. Good thing is the azure gem has a .get_blob_properties method to only request the meta info, but I don't find a way to make this work with the .read method. Any suggestion?

markevans commented 6 years ago

hi - cool to see the custom data store. Because of the simplicity of the datastore interface, yes it will be expensive to get the name like you say. The usual workaround is to store the name separately, outside the store, e.g. if you're using Rails you'd use the name magic attribute http://markevans.github.io/dragonfly/models#magic-attributes by simply adding the image_name column as well as the image_uid you already have. Is this something you can do in your case?

alagos commented 6 years ago

@markevans sorry for late reply, but at the end I added an extra field for metadata, because the problem was not only with name, but also with filesize. Maybe not the best solution, but at least fixed my problem