versions plugin: "isn't valid uploaded file data"

527 views
Skip to first unread message

michae...@gmail.com

unread,
Jan 7, 2017, 3:58:12 AM1/7/17
to Shrine
I try to transcode uploaded video file in project based on shrine-tus-demo and fail to do so.

Here's my code:

require "./config/shrine"
require 'streamio-ffmpeg'
require 'byebug'

class VideoUploader < Shrine
  plugin :determine_mime_type
  plugin :restore_cached_data
  plugin :processing
  plugin :versions

  process(:store) do |io, context|
    # byebug

    mov = io.download
    video      = Tempfile.new(["video", ".h264"], binmode: true)
    screenshot = Tempfile.new(["screenshot", ".jpg"], binmode: true)

    movie = FFMPEG::Movie.new(mov.path)
    movie.transcode(video.path)
    movie.screenshot(screenshot.path)
    mov.delete
    
    {original: io, video: video, screenshot: screenshot}
  end
end

Here's the output of "Movie.first.video" after uploading and promoting:

irb(main):041:0> Movie.first.video
I, [2017-01-07T11:51:21.944015 #88104]  INFO -- : (0.000221s) SELECT * FROM "movies" LIMIT 1
Shrine::Error: {"original"=>{"id"=>"1d2559a120cf172bc7aefab1dbba1092.mp4", "storage"=>"store", "metadata"=>{"filename"=>"hero2.mp4", "size"=>86499387, "mime_type"=>"video/mp4"}}, "video"=>{"id"=>"935e4c25e09356a683e9c65d87a1fcfb.h264", "storage"=>"store", "metadata"=>{"filename"=>"video20170107-94245-1xeyoly.h264", "size"=>8781747, "mime_type"=>"application/octet-stream"}}, "screenshot"=>{"id"=>"be2bda285797aca552ba8a37a94b41db.jpg", "storage"=>"store", "metadata"=>{"filename"=>"screenshot20170107-94245-14niirf.jpg", "size"=>39997, "mime_type"=>"image/jpeg"}}} isn't valid uploaded file data
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:713:in `initialize'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:172:in `new'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:172:in `uploaded_file'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:626:in `uploaded_file'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:624:in `uploaded_file'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:592:in `get'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:404:in `video'
from (irb):41
from /Users/user/.rbenv/versions/2.3.3/bin/irb:11:in `<main>'

I try to get files from the hash, but get the same error:

irb(main):043:0> Movie.first.video[:original]
I, [2017-01-07T11:53:43.019084 #88104]  INFO -- : (0.000239s) SELECT * FROM "movies" LIMIT 1
Shrine::Error: {"original"=>{"id"=>"1d2559a120cf172bc7aefab1dbba1092.mp4", "storage"=>"store", "metadata"=>{"filename"=>"hero2.mp4", "size"=>86499387, "mime_type"=>"video/mp4"}}, "video"=>{"id"=>"935e4c25e09356a683e9c65d87a1fcfb.h264", "storage"=>"store", "metadata"=>{"filename"=>"video20170107-94245-1xeyoly.h264", "size"=>8781747, "mime_type"=>"application/octet-stream"}}, "screenshot"=>{"id"=>"be2bda285797aca552ba8a37a94b41db.jpg", "storage"=>"store", "metadata"=>{"filename"=>"screenshot20170107-94245-14niirf.jpg", "size"=>39997, "mime_type"=>"image/jpeg"}}} isn't valid uploaded file data
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:713:in `initialize'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:172:in `new'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:172:in `uploaded_file'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:626:in `uploaded_file'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:624:in `uploaded_file'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:592:in `get'
from /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/shrine-2.5.0/lib/shrine.rb:404:in `video'
from (irb):43
from /Users/user/.rbenv/versions/2.3.3/bin/irb:11:in `<main>'

I wonder what am I doing wrong?

michae...@gmail.com

unread,
Jan 7, 2017, 4:08:15 AM1/7/17
to Shrine, michae...@gmail.com
And the other question is: how to change mime_type here from 'application/octet-stream' to 'video/H264' for h264 file?

michae...@gmail.com

unread,
Jan 7, 2017, 4:51:25 AM1/7/17
to Shrine, michae...@gmail.com
I got this last question solved with

  plugin :determine_mime_type, analyzer: :mime_types

but the "isn't valid uploaded file data" error persists. Seems to me that versions plugin is broken. I can transcode in process(:store) block and return transcoded file without problems, but as soon as I return hash, I encounter the error. I tried different values for the hash with the same result.

Janko Marohnić

unread,
Jan 8, 2017, 1:52:09 AM1/8/17
to Mikhail Vasin, Shrine
I tried reproducing with this script (I commented out the FFMPEG part because I don't have ffmpeg installed at the moment):


require "shrine"

require "shrine/storage/file_system"

require "tempfile"

require 'streamio-ffmpeg'


Shrine.storages = {

  cache: Shrine::Storage::FileSystem.new("uploads"),

  store: Shrine::Storage::FileSystem.new("uploads"),

}


Shrine.plugin :sequel


class VideoUploader < Shrine

  plugin :determine_mime_type

  plugin :restore_cached_data

  plugin :processing

  plugin :versions


  process(:store) do |io, context|

    mov = io.download

    video      = Tempfile.new(["video", ".h264"], binmode: true)

    screenshot = Tempfile.new(["screenshot", ".jpg"], binmode: true)


    # movie = FFMPEG::Movie.new(mov.path)

    # movie.transcode(video.path)

    # movie.screenshot(screenshot.path)

    # mov.delete


    {original: io, video: video, screenshot: screenshot}

  end

end


require "sequel"


DB = Sequel.sqlite

DB.create_table(:movies) do

  primary_key :id

  column :video_data, :text

end


class Movie < Sequel::Model

  include VideoUploader[:video]

end


movie = Movie.create(video: File.open("/path/to/file"))

puts movie.video



But loading the video objects worked without any errors. This error looks exactly like the error you would get if you didn't load the versions plugin (because then Shrine would attempt to instantiate the Shrine::UploadedFile object with the versions data, which fails with this error). But then uploading a hash of versions would fail as well.

It would be great if you could try to reproduce this error in a self-contained script, you can just modify the one above. There is an ActiveRecord template in CONTRIBUTING.md if you're using ActiveRecord.

Kind regards,
Janko


--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine+unsubscribe@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/a62c2e0d-c408-4afc-bc0b-b7e8cbea196d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

michae...@gmail.com

unread,
Jan 10, 2017, 9:41:17 AM1/10/17
to Shrine, michae...@gmail.com
I didn't even think I could pack almost everything within one file, thanks for the idea! I couldn't reproduce the problem with this one-file setup, and somehow the bug went away from my own code as well. So this problem problem is gone.

From now on, every time I have a problem I try to replay it in the same one-file setup, and most of the time it gets solved along the way.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine...@googlegroups.com.

To post to this group, send email to ruby-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages