ActiveStorage to upload large base64 encoded string?

。_饼干妹妹 提交于 2019-12-05 09:18:52

As far as I know, Active Storage has currently no native support for that.

Maybe this Rails issue has further information helpful to you.

We have implemented Data URI uploads with Shrine (and its DataURI Plugin) and are waiting until there is a proper way to do this with Active Storage before we will migrate.

You can do something like this:

decoded_data = Base64.decode64(params[:base64].split(',')[1])
resource.image = { 
  io: StringIO.new(decoded_data),
  content_type: 'image/jpeg',
  filename: 'image.jpg'
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!