Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve a file & cache it (process! called twice) #545

Closed
elmatou opened this issue Nov 30, 2011 · 3 comments
Closed

Retrieve a file & cache it (process! called twice) #545

elmatou opened this issue Nov 30, 2011 · 3 comments

Comments

@elmatou
Copy link

elmatou commented Nov 30, 2011

Hi,
I'm building an online safe based on carrierwave and a personal cipher library.
My needs are quite simple, I want a user to upload a file, my Rails app encrypt it, then store it (using Fog) in any datacenter.
Then, when retrieving the file, my app needs to decrypt it from cache, and send it to the user.

My uploader :

class EncryptorUploader < CarrierWave::Uploader::Base
  storage :fog

  before :store, :remember_cache_id
  after :store, :delete_tmp_dir

  process :encrypt

  def encrypt
    cache_stored_file! if !cached?
    #.... Encryption logic altering the cached file in place
  end

  ...
end

How I want to use it (here without activerecord for now):

  @uploader = EncryptorUploader.new(FakeClass.new, :fake)
  @uploader.store!(File.open(__FILE__))
  ...
  #... Years later, I need to get the file back
  @uploader.retrieve_from_store!(@uploader.identifier)
  @uploader.cache_stored_file!
  #... Decryption logic altering the cached file in place
  @uploader.read

But process! is called twice, once on store!, which is quite normal, but also on cache_stored_file! (which call cache! too)
Meaning that when I want to retrieve the file, it is double encrypted...

I'm not understanding, if I misuse Carrierwave, or if there is an issue in the cache_stored_file! feature/code.
BTW cache_stored_file! have no test, so I was unable to check what was the point of this method.

Anybody have any though on my case ?

I'm ready to help writing code and test case on this feature or in a new feature matching my needs.

PS : I checked for issue #380 & #422 but it seems to be a different case.

@trevorturk
Copy link
Contributor

Is there a reason you need to call cache_stored_file! in your encrypt method? I think you're just supposed to return the processed file at the end of your custom method.

@elmatou
Copy link
Author

elmatou commented Dec 25, 2011

Hi Trevor,
Thx for looking at this.
I do not know with which web server I'm gonna interact with, and I'm not sure my Rails app will be allowed to write to the file location. Since then I built a method around openssl that cipher the file in place.
I would be glad to cipher the file in webserver temporary place (less copy means less resource and more security), but I don't think it is cross-compatible.

Anyhow I also wanted to point that cache_stored_file! behavior's seems awkward.

@trevorturk
Copy link
Contributor

Gotcha. Well, if you'd like to work up a pull request (with tests!) that demonstrates the problem with a proposed fix, that would be awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants