我正在尝试将文件上传到 Wistia.com。从 params 获取 path_to_video 变量的正确方法是什么,因为它是一个 ActionDispatch 对象。
控制器是这样的:
def create
post_video_to_wistia(params[:upload][:file].tempfile)
end
上传代码看起来像这样
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
以下是参数:
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"}