1. When you define store_dir
.. filename it seems NIL !!
There seems to be an immediate error - try the puts
statement to print what file name is set to.
If the file name is NIL, you will see the error message that you see:
You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[] app/uploaders/image_uploader.rb:17:in `store_dir'
NOTE.
you override both file_name and store_dir ... and use the file name inside the store_dir definition ... There might be a chicken and egg problem here. Better check that
store_dir should just be a directory, for example. /somewhere/on/your/disk/images
filename should be just a filename without a path, for example. 24371592d9ea16625854ed68ac4b5846
, or 24371592d9ea16625854ed68ac4b5846.jpg
eg. check how these two are used in the code in store.rb
(at the end below)
Question:
using filename[0,2]
- do you use directories with a 2-letter prefix MD5-sum to store images?
2. Side note: What is current_path
? Seems wrong. There must be a path + file name, not just a path
3. Check the second code snippet (below) from store.rb
It looks like you set store_dir
in a relative directory - it's very fragile and error prone .. it would be better to set it to an absolute path (starting with '/')
4. Try specifying the file name and store_dir for constants for debugging
As a health check, this works when you do this:
def store_dir '/tmp/'
which should work before setting the file name to the amount of MD5.
From the source code: (0.5.7)
Library / carrierwave / storage / file.rb
Library / carrierwave / downloader / store.rb
You can override CarrierWave :: Uploader :: Store # file_name to specify the file name of your choice (see source code):
Redefinition in CarrierWave :: Uploader :: Base should work because "Store" is included in "Base"; this overrides the default file name.
From store.rb
You can also check the cached file name, calculate the MD5 sum (or better SHA1 sum ) on it, and then use the result for the file name.
From store.rb
File Equality:
files_equal?( filename1, filename2 ) return true if File.size(filename1) == File.size(filename2)