Method: GrandCloud::Video#upload

Defined in:
lib/grand_cloud/video.rb

#upload(title, file, options = {}, pass_encoding = false, &block) ⇒ Object

upload is an async method you should pass an original_filename on options when you uploading a temp file



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/grand_cloud/video.rb', line 42

def upload title, file, options={}, pass_encoding=false, &block
  return EM.stop if ((file.class == Tempfile) && (!options[:original_filename])) || !block_given?

  pn_file = Pathname(file)

  title = get_video_title(title, options[:original_filename], pn_file)
  extname = get_video_extname(options[:original_filename], pn_file)

  self.create(title, pass_encoding) do |rep| 

    return block.call(nil) unless rep

    GrandCloud.logger.warn(rep)

    req = Base.file_upload({
      :method => 'post',
      :uri => '/vmsUpload.htm',
      :url => rep['uploadUrl'],
      :pn_file => pn_file,
      :host => rep['uploadUrl'].gsub(/^http:\/\/(.+)\/.+/, '\1'),
      :request_params => {
        :sid => rep['sid'],
        :cfrom => 'client',
        :filesize => pn_file.size,
        :ext => extname
      },
      :timeout => {
        :inactivity_timeout => 0
      }

    })
    callback(req, block.to_proc, rep.select{|k, v| %W{sid vid}.include?(k)})
  end
end