By default, CarrierWave copies an uploaded file twice, first copying the file into the cache, then copying the file into the store.
清空了 public/uploads/tmp,再上传图片,为什么这里不出现了 (first copying the file into the cache)??代码没动过
应该 carrierwave 首先缓存在 public/uploads/tmp,然后会转存在 public/uploads/[class_name_in_dash] 中。(前提是你用缺省配置)
By default, CarrierWave copies an uploaded file twice, first copying the file into the cache, then copying the file into the store.
@ericguo 这里说的就是啊,我没动过 code,没设置过
def move_to_cache
true
end
我就是把 public/uploads/tmp 清空了
def cache!(new_file)
107 new_file = CarrierWave::SanitizedFile.new(new_file)
108
109 unless new_file.empty?
110 raise CarrierWave::FormNotMultipart if new_file.is_path? && ensure_multipart_form
111
112 with_callbacks(:cache, new_file) do
113 self.cache_id = CarrierWave.generate_cache_id unless cache_id
114
115 @filename = new_file.filename
116 self.original_filename = new_file.filename
117
118 if move_to_cache
119 debugger #调试进到这里,但cache_path = true,这里是否应该是路径str?
120 @file = new_file.move_to(cache_path, permissions)
121 else
#6 楼 @kee 看代码,cache_path 应该是一个路径才对。 https://github.com/carrierwaveuploader/carrierwave/blob/357f71e0797764a1760ce7a12c40ef19780ce6ce/lib/carrierwave/uploader/cache.rb#L158
def cache_path
File.expand_path(File.join(cache_dir, cache_name), root)
end
By default, CarrierWave copies an uploaded file twice, first copying the file into the cache, then copying the file into the store. For large files, this can be prohibitively time consuming.
这里写 copy twice,我上传时注意了下 public/photos/tmp 目录,显示生成了 cache 然后传到 server 接着 cache 删除了(是 move 吧?)
我在 uploader 里添加
def move_to_cache
true
end
def move_to_store
true
end
cache 就保留下来了,但是 wiki 里是这样
When the move_to_cache and/or move_to_store methods return true, files will be moved (instead of copied) to the cache and store respectively.
@ruby_sky 如果默认是 copy 那 cache 不应改清掉,设置 move_to = true 反而表面上让我感觉是 copy? 请简单描述下 CarrierWave 上传流程(文件 -》cache -》server?) cc @Martin91
https://github.com/carrierwaveuploader/carrierwave 有关 Large files 段(上边引用的),我是否理解错了?? 改为 move_to = true,会否增加上传耗时?
def move_to_cache
true
end
def move_to_store
true
end