CarrierWave has amazing documentation, until you need to do it without a model!
I have my uploader and fog settings set up, and they all work fine when using the mounted uploader on a model, but now I want to do it without a model.
I have this:
uploader = CsvUploader.new
something = uploader.store!(File.read(file_path))
uploader.retrieve_from_store!(self.file_name)
When I call .store! the code runs immediately which is weird since it should take a few seconds to upload the file?
Then after I call .retrieve_from_store! the uploader object has all the correct S3 info, like the full urls and stuff.
However, calling:
uploader.file.exists?
returns false. And browsing the s3 urls return a key not found error from s3.
So, what am I doing wrong?? To reiterate, it works when mounted so I don't think it's my fog settings.
My uploader:
class CsvUploader < CarrierWave::Uploader::Base
# Choose what kind of storage to use for this uploader:
storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
include CarrierWave::MimeTypes
process :set_content_type
def store_dir
"uploads/public/extranet_csvs"
end
def cache_dir
"/tmp/uploads"
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(csv)
end
end
File.open(file_path)
like this will leave the file open after it's stored. To have Ruby close it for you, useFile.open(file_path) { |file| something = uploader.store!(file) }
– Pruitt