【问题标题】:Rails 5.2 ActiveStorage crop attachment before upload上传前的 Rails 5.2 ActiveStorage 裁剪附件
【发布时间】:2019-06-12 00:26:19
【问题描述】:

我可以使用 view 调整 avatar 的大小

<%= image_tag @user.avatar.variant(resize: "100x100")

但我想知道是否有办法在实际上传头像之前调整它的大小。

当我在 controller 中运行同一行时,我收到此错误:

undefined method `variant' for # <ActionDispatch::Http::UploadedFile:0x00007fcecfdac190>

【问题讨论】:

    标签: ruby-on-rails variant rails-activestorage


    【解决方案1】:

    为了在上传之前调整大小,您可以使用 HTML5 画布元素 + Javascript 进行所需的处理,然后将图像发送到服务器。

    Check this question了解更多详情。

    【讨论】:

      猜你喜欢
      • 2019-02-24
      • 2018-02-02
      • 2019-05-19
      • 2018-11-05
      • 2021-09-04
      • 2018-10-20
      • 2018-09-28
      • 2023-01-31
      • 1970-01-01
      相关资源
      最近更新 更多