gpt4 book ai didi

ruby-on-rails - 带有自定义处理器的 CarrierWave 未注册

转载 作者:数据小太阳 更新时间:2023-10-29 07:08:32 25 4
gpt4 key购买 nike

我正在使用 carrierwave上传视频然后有一个名为 thumb 的版本,带有自定义处理器,可以获取视频并使用 streamio-ffmpeg 创建屏幕截图。视频和文件都已正确上传,但在调用 uploader.url(:thumb) 时我得到:

ArgumentError: Version thumb doesn't exist!

VideoUploader.rb

require 'carrierwave/processing/mime_types'
require 'streamio-ffmpeg'

class VideoUploader < CarrierWave::Uploader::Base
include CarrierWave::VideoConverter
include CarrierWave::MimeTypes

process :set_content_type

storage :file

version :thumb do
process :create_thumb

#def full_filename(for_file)
# "thumb_#{File.basename(for_file, File.extname(for_file))}.png"
#end
end

def create_thumb
cached_stored_file! if !cached?

movie = FFMPEG::Movie.new(current_path)

dirname = File.dirname(current_path)

thumb_path = "#{File.join(dirname, File.basename(path, File.extname(path)))}.png"

movie.screenshot(thumb_path, :seek_time => 5)
File.rename thumb_path, current_path
end

def file_identifier
model[:video]
end

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
return "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.user_id}/#{model.id}"
end
end

然后 model.video_url(:thumb) 返回参数错误。我不确定该怎么做或为什么版本未注册任何帮助都很好,谢谢。

最佳答案

修复

导致错误的原因是重启服务器而不是重启 Rails 控制台。一旦我这样做了,参数错误就消失了,但我走错了路。所以我取消评论

        def full_filename(for_file)
"thumb_#{File.basename(for_file, File.extname(for_file))}.png"
end

和使用

[model].video.recreate_versions!

更正路径或命名方案中可能发生的任何错误

关于ruby-on-rails - 带有自定义处理器的 CarrierWave 未注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13202992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com