我有一个带有视频活动存储附件的Rails模型。现在,当我想为该附件创建图像预览时,看似已创建了预览,但是结果是视频,而不是应有的图像。尽管代码没有更改,但整个过程一直持续到最近。我的代码如下所示:
class MyModel < ApplicationRecord
has_one_attached :video # The video attachment is fine and can be retrieved and viewed
def get_preview
if video.attached? and video.previewable? # => true
img_preview = video.preview(resize: "800x1400").processed # Returns an active storage instance with the file type mp4 instead of the expected png thumbnail
return img_preview.service_url # Fails with exception (see next snippet)
end
end
这是我尝试检索预览的url时抛出的异常:
MiniMagick::Error: `identify -format %[orientation] /tmp/ActiveStorage20191128-4-1t9vihl.png[0]` failed with error:
2019-11-28T17:02:42.618871+00:00 app[worker.1]: identify-im6.q16: improper image header `/tmp/ActiveStorage20191128-4-1t9vihl.png' @
以前有人遇到过吗? Active Storage预览API的文档实际上不存在,因此我不确定从哪里开始。