How to extract a path from an ActionDispatch object
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"}
No comments:
Post a Comment