CarrierWave how to store file at given url

前端 未结 3 1295
春和景丽
春和景丽 2020-12-25 13:44

I have CarrierWave working fine through the typical ORM setup and upload via form. I would like to figure out how to use CarrierWave outside of the form submission context.

3条回答
  •  青春惊慌失措
    2020-12-25 14:32

    Actually you can do this using the built in remote_{attribute}_url property if you are using the active record/model helpers (see the CarrierWave railscast for the details). However, I dug around in the source code a bit to see how this actually works and it appears that even if you are not you should be able to use the following:

    uploader = ImageUploader.new
    uploader.download! some_remote_url
    uploader.store!
    

    Give it a try.

提交回复
热议问题