简体   繁体   English

如何将本地文件上传到Carrierwave模型?

[英]How to upload a local file to a Carrierwave model?

I'm using Carrierwave to handle image uploads, but I'm not using a form, instead I use local files in the server. 我正在使用Carrierwave来处理图像上传,但我没有使用表单,而是使用服务器中的本地文件。

How can I make this work? 我怎样才能做到这一点?

@user = User.first
image_path = "/tmp/pic-s7b28.jpg"

@user.image = image_path
@user.save!
@user = User.first
image_path = "/tmp/pic-s7b28.jpg"

@user.image = File.open(image_path)
@user.save!

You can check examples in the carrierwave readme 您可以查看carrierwave自述文件中的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM