我目前在将项目从Paperclip移动到ActiveStorage时遇到问题。更准确地说,我遇到了ActiveStorage和存储svg图像的问题。
我知道svg文件是图像,但是……
Svg被认为是二进制内容类型,因此这就是Active存储svg链接表示为下载附件链接的原因。您可以在此链接中查看所有content_types和限制 https://github.com/rails/rails/blob/master/activestorage/lib/active_storage/engine.rb 。
有关此限制和解释的更多信息,请访问: http://github.com/jdelStrother/rails/commit/06ab7b27ea1c1ab357085439abacdb464f6742bf 。我会为此发布一个问题。也许他们将来会修复它
将此代码添加到config / application.rb:
# Hack for allowing SVG files. While this hack is here, we should **not** # allow arbitrary SVG uploads. https://github.com/rails/rails/issues/34665 ActiveStorage::Engine.config .active_storage .content_types_to_serve_as_binary .delete('image/svg+xml')
您当然可以删除评论:)。希望能帮助到你。