我的上传器文件
for
我正在上传# creates a `list` and binds it to name "a"
a = [1, 2, 3]
# get the object bound to name "a" and binds it to name "b" too.
# at this point "a" and "b" both refer to the same `list` instance
b = a
print id(a), id(b)
print a is b
# so if we mutate "a" - actually "mutate the object bound to name 'a'" -
# we can see the effect using any name refering to this object:
a.append(42)
print b
# now we rebind "a" - make it refer to another object
a = ["a", "b", "c"]
# at this point, "b" still refer to the first list, and
# "a" refers to the new ["a", "b", "c"] list
print id(a), id(b)
print a is b
# and of course if we now mutate "a", it won't reflect on "b"
a.pop()
print a
print b
图片,当我尝试从上传文件中读取元数据时,一切都将丢失。有没有办法在上传时保留它?
答案 0 :(得分:1)
随意搜索会返回宝石Carrierwave-meta。基本上,添加到您的gemfile:
./adb install -r <path-to-apk>
然后运行gem 'carrierwave-meta'
。然后将bundle install
选项添加到您的上传器中:
store_meta
当然,您需要确保您的模型可以存储值:
class TestUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
include CarrierWave::Meta
process :store_meta => [{md5sum: true}]
version :version do
process :resize_to_fill => [200, 200]
process :store_meta
end
end
file = File.open('test.jpg') # JPEG 500x300, 20000 bytes
uploader = TestUploader.new
uploader.store!(file)
uploader.width # 500
uploader.height # 300
uploader.image_size # [500, 300]