【发布时间】:2017-07-05 17:14:44
【问题描述】:
我希望使用带有 cURL 的 Streamable API 和 PHP 来构建视频上传。 https://streamable.com/documentation#upload-video-file
我想要完成的是:
- 用户填写信息表并从他们的计算机/设备中选择要上传的视频文件
- 提交表单,PHP 从那里处理它以与 Streamable API 对话,通过表单将视频上传到我的 Streamable 帐户,然后从 Streamable 返回短代码,让我将其其余信息存储在 MySQL 数据库中
我已经成功地尝试通过终端使用 curl 命令。但是,我在通过 php 表单提交将其关闭时遇到了问题。
这是我在终端中使用的命令上传的示例,该命令有效:
curl https://api.streamable.com/upload -u my_email:my_pass -F file=@path/to/file.mp4
借助大量在线帮助,我有了一个非常简单的 cURL 脚本。我想你可以说我对使用 cURL 很陌生。
$url = 'https://api.streamable.com/upload -u my_email.com:my_pass -F file=@path/to/file.mp4';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
这样,我收到了 HTTP 400 错误。 https://streamable.com/documentation#errors
.. 400 范围内的代码表示客户端错误...
我想这就是我在这里搞砸的原因?
我尝试过这种方式,但我得到了同样的错误。
$pass = 'my_email:my_pass';
$postFields = array(
'file' => '/path/to/file.mp4',
'title' => 'Example Title'
);
$url = 'https://api.streamable.com/upload';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, $pass);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
我使用print_r(curl_getinfo($ch)); 来查看正在发生的事情,这就是它吐出的内容 - 也许这对一些帮助有用:
Array ( [url] => https://api.streamable.com/upload
-u my_email:my_pass -F file=@/Path/to/file.mp4 [content_type] => [http_code] => 400 [header_size] => 66 [request_size] => 277 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.36033 [namelookup_time] => 0.00138 [connect_time] => 0.082871 [pretransfer_time] => 0.283219 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 275 [starttransfer_time] => 0.36031 [redirect_time] => 0 [redirect_url] => [primary_ip] => xx.xx.xxx.xxx [certinfo] => Array ( ) [primary_port] => 443 [local_ip] => 192.168.0.1 [local_port] => 57288 )
【问题讨论】: