How to save an image from a url with rails active storage?

后端 未结 3 1768
野的像风
野的像风 2020-12-29 07:46

I\'m looking to save a file (in this case an image) located on another http web server using rails 5.2 active storage.

I have an object with a string parameter for s

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 08:10

    using the down gem to avoid the security issues of using open-uri:

    image = Down.download(image_url)
    user.image.attach(io: image, filename: "image.jpg")
    

提交回复
热议问题