【问题标题】:Can't upload blob URL to Active Storage (ActiveSupport::MessageVerifier::InvalidSignature)无法将 blob URL 上传到 Active Storage (ActiveSupport::MessageVerifier::InvalidSignature)
【发布时间】:2021-08-11 07:21:40
【问题描述】:

我想将在 Web 上获取的数据存储在 Rails 中的 Active Storage 中。但是,数据未正确保存,video_tag 出现错误。

我已成功创建 Blob 数据,但无法上传。

错误

ActiveSupport::MessageVerifier::InvalidSignature

<%= f.hidden_field :media, id: "download-video" %>

// => <input id="download-video" type="hidden" value="blob:http://localhost:3000/859031b4-022b-4e7e-be08-518c77e8e9d1" name="post[media]">

app/models/post.rb

class Post < ApplicationRecord
  belongs_to :user
  has_one_attached :media
end

app/models/posts_controller.rb

---
def create
  @post = current_user.posts.create(create_params)
  @post.save
end
---

【问题讨论】:

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


    【解决方案1】:

    只要我明白你要做什么,你就不能这样。

    请注意,发送带有input 值设置为某个 URL 的表单会将字符串发送到服务器,但它需要文件。

    一种解决方案是在控制器中创建Post 之前下载文件。

    Similar problem

    【讨论】:

    • 谢谢你的回答,我会想办法下载的。