Carrierwave 没有那个文件或目录
Carrierwave no such file or directory
我正在尝试编写一种使用 EXIFR gem 检索使用 Carrierwave 上传的照片的数据(在本例中为相机型号)的方法。我正在使用的当前方法在我的模型中看起来像这样:
before_save :get_exif_data
def get_exif_data
imgfile = EXIFR::JPEG.new(photo.filename)
return
self.model = imgfile.model
end
但是,我得到一个错误 "No such file or directory - IMG_0953.JPG"(或另一个文件名)。
我的目标是在保存前使用 EXIFR gem 的 .model 方法提取 "type of camera" 数据。来自 EXIFR gem 文档:
EXIFR::JPEG.new('IMG_6841.JPG').model # => "Canon PowerShot G3"
错误告诉我我的 photo.filename 尚未创建。在保存图像之前如何处理图像?
尝试
EXIFR::JPEG.new(Rails.root.to_s + photo.filename_url)
载波 return url 看起来像 /uploads/...
它是webapp的相对路径,但是EXIFR::JPEG
会认为它是系统文件的路径
实际上,像下面这样的东西最终对我有用:
before_save :get_camera
private
def get_camera
self.model = EXIFR::JPEG.new(photo.file.path).model
end
end
我正在尝试编写一种使用 EXIFR gem 检索使用 Carrierwave 上传的照片的数据(在本例中为相机型号)的方法。我正在使用的当前方法在我的模型中看起来像这样:
before_save :get_exif_data
def get_exif_data
imgfile = EXIFR::JPEG.new(photo.filename)
return
self.model = imgfile.model
end
但是,我得到一个错误 "No such file or directory - IMG_0953.JPG"(或另一个文件名)。
我的目标是在保存前使用 EXIFR gem 的 .model 方法提取 "type of camera" 数据。来自 EXIFR gem 文档:
EXIFR::JPEG.new('IMG_6841.JPG').model # => "Canon PowerShot G3"
错误告诉我我的 photo.filename 尚未创建。在保存图像之前如何处理图像?
尝试
EXIFR::JPEG.new(Rails.root.to_s + photo.filename_url)
载波 return url 看起来像 /uploads/...
它是webapp的相对路径,但是EXIFR::JPEG
会认为它是系统文件的路径
实际上,像下面这样的东西最终对我有用:
before_save :get_camera
private
def get_camera
self.model = EXIFR::JPEG.new(photo.file.path).model
end
end