How to upload a local file to a Carrierwave model?

前端 未结 1 1507
难免孤独
难免孤独 2021-02-07 13:22

I\'m using Carrierwave to handle image uploads, but I\'m not using a form, instead I use local files in the server.

How can I make this work?

@user = Use         


        
1条回答
  •  [愿得一人]
    2021-02-07 14:09

    @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

    0 讨论(0)
提交回复
热议问题