CarrierWave拥有令人惊叹的文档,直到您需要在没有模型的情况下完成它!
我设置了我的上传器和雾设置,并且在模型上使用已安装的上传器时它们都能正常工作,但现在我想在没有模型的情况下完成它.
我有这个:
uploader = CsvUploader.new
something = uploader.store!(File.read(file_path))
uploader.retrieve_from_store!(self.file_name)
Run Code Online (Sandbox Code Playgroud)
当我打电话给.store!代码立即运行,这很奇怪,因为上传文件需要几秒钟?
然后我打电话给.retrieve_from_store!上传器对象具有所有正确的S3信息,如完整的URL和内容.
但是,致电:
uploader.file.exists?
Run Code Online (Sandbox Code Playgroud)
返回false.浏览s3网址会从s3返回一个未找到密钥的错误.
那么,我做错了什么?重申一下,它在安装时有效,所以我不认为这是我的雾设置.
我的上传者:
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 …Run Code Online (Sandbox Code Playgroud)