我在 Rails 5 中使用 Shrine gem。我启用了插件 upload_endpoint、versions、processing 和 recache。我希望在上传端点响应中获得生成的版本。
class VideoUploader < Shrine
plugin :processing
plugin :versions
plugin :recache
plugin :upload_endpoint
plugin :upload_endpoint, rack_response: -> (uploaded_file, request) do
# ??? I expected uploaded_file to have thumbnail version here ???
body = { data: uploaded_file.data, url: uploaded_file.url }.to_json
[201, { "Content-Type" => "application/json" }, [body]]
end
process(:recache) do |io, context|
versions = { original: io }
io.download do |original|
screenshot = Tempfile.new(["screenshot", ".jpg"], binmode: true)
movie = FFMPEG::Movie.new(original.path)
movie.screenshot(screenshot.path)
screenshot.open # refresh file descriptors
versions[:thumbnail] = screenshot
end
versions
end
end
为什么只有在保存整个记录时才会发生进程回调进程(:recache)?以及如何使其在直接上传后立即生成版本?