我尝试使用Laravel和GuzzleHttp将视频上传到DailyMotion。这是我的代码:
$file = "3.mp4";
$fields["file"] = fopen($file, 'rb');
$res = $client->post($upload_url, [
'headers' => ['Content-Type' => 'multipart/form-data'],
$fields
]);
$data3 = $res->getBody();
$response_upload_video = json_decode($data3,true);
echo "<br>Getting dm upload video response: ";
print_r($response_upload_video);
$upload_url
是DailyMotion传递的动态生成的URL。执行上面的代码后,我总是会收到此错误:
Production.ERROR:GuzzleHttp \ Exception \ ClientException:
客户端错误: POST http://upload-02.sg1.dailymotion.com/upload?uuid=werewkrewrewrwer&seal=pppppppppppppppp`导致 在400 Bad Request响应中:
{&#34;错误&#34;:&#34;无效的内容范围&#34;,&#34;封印&#34;:&#34; yyyyyyyyyyyyyyyyyyy&#34;} 在/home/vagrant/Code/svc-titus/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111
答案 0 :(得分:2)
我认为你不需要指定内容类型标题guzzle会在你提供资源时自动决定它也是你的视频路径似乎有问题如果视频存储在公共目录你需要使用public_path或相应的路径辅助函数来获取其物理路径 下面应该在guzzleHttp 6中检查发送表单文件 http://docs.guzzlephp.org/en/latest/quickstart.html#uploading-data
$file = "3.mp4";
$res = $client->post($upload_url, [
'multipart' => [
[
'name' => 'file',
'contents' => fopen(base_path($file), 'r') // give absolute path using path helper function
]
]
]);
$data3 = $res->getBody();
$response_upload_video = json_decode($data3,true);
echo "<br>Getting dm upload video response: ";
print_r($response_upload_video);