0

I'm trying to upload a file to Wistia.com. What is the correct way to get the path_to_video variable from params as it's an ActionDispatch object.

The controller is something like this:

def create
 post_video_to_wistia(params[:upload][:file].tempfile)
end

The upload code looks something like this

def post_video_to_wistia(path_to_video)
  uri = URI('https://upload.wistia.com/')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  request = Net::HTTP::Post::Multipart.new uri.request_uri, {
  'api_password' => [WISTIA_PASSWORD],
  'file' => UploadIO.new(File.open(path_to_video),
  'application/octet-stream',
  File.basename(path_to_video)
    )
  }
  response = http.request(request)
  return response
end

Here are the params:

Parameters: {"upload"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x007fa8201d58d8 @original_filename="123.mp4", @content_type="video/mp4", @headers="Content-Disposition: form-data; name=\"upload[file]\"; filename=\"123.mp4\"\r\nContent-Type: video/mp4\r\n", @tempfile=#<File:/var/15741-1xiizbz>>}, "commit"=>"Send", "id"=>"2"}
grabury
  • 4,797
  • 14
  • 67
  • 125

2 Answers2

0

params[:file] will get you the ActionDispatch object, you then take anything you need from it.

bluehallu
  • 10,205
  • 9
  • 44
  • 61
  • I tried this post_video_to_wistia(params[:upload][:file]) and 'file' => UploadIO.new( file.tempfile, 'application/octet-stream', file.original_filename ) – grabury Aug 22 '13 at 13:22
-1

I got this error when I forgot to add:

mount_uploader :image, ImageUploader

to the model that gets the image assigned to it, where ':image' is the name of your file field.

If your file fields name is not 'image' you must change :image and ImageUploader to reflect your names i.e.

mount :picture, PictureUploader 
Zack Weiner
  • 664
  • 4
  • 14