Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CarrierWave with custom processor not registering

I am using carrierwave to upload a video then have a version called thumb with a custom processor that takes the video and creates a screenshot using streamio-ffmpeg. Both the video and the file are uploaded correctly but when calling uploader.url(:thumb) I get:

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

Then model.video_url(:thumb) returns the argument error. I am not sure what to do or why the version isn't registered any help would be great, thanks.

like image 351
skukx Avatar asked Nov 02 '12 21:11

skukx


1 Answers

Fix

What contributed to the error was a mix of restarting the server but not restarting the rails console. Once i did this the Argument error went away but I was getting the wrong path. So i uncommented

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

and used

[model].video.recreate_versions!

to correct any errors in the paths or naming schemes that could have occured

like image 128
skukx Avatar answered Sep 21 '22 22:09

skukx