【发布时间】:2018-03-24 10:39:03
【问题描述】:
我有一个可以上传视频并将其发送到远程目的地的表单。我有一个 cURL 请求,我想使用 Guzzle 将其“翻译”为 PHP。
到目前为止,我有这个:
public function upload(Request $request)
{
$file = $request->file('file');
$fileName = $file->getClientOriginalName();
$realPath = $file->getRealPath();
$client = new Client();
$response = $client->request('POST', 'http://mydomain.de:8080/spots', [
'multipart' => [
[
'name' => 'spotid',
'country' => 'DE',
'contents' => file_get_contents($realPath),
],
[
'type' => 'video/mp4',
],
],
]);
dd($response);
}
这是我使用的 cURL,我想翻译成 PHP:
curl -X POST -F 'body={"name":"Test","country":"Deutschland"};type=application/json' -F 'file=@C:\Users\PROD\Downloads\617103.mp4;type= video/mp4 ' http://mydomain.de:8080/spots
所以当我上传视频时,我想替换这个硬编码
C:\Users\PROD\Downloads\617103.mp4.
当我运行这个时,我得到一个错误:
客户端错误:
POST http://mydomain.de:8080/spots导致400 Bad Request响应:请求正文无效:期望表单值“body”客户端错误:
POST http://mydomain.de/spots导致400 Bad Request响应: 请求正文无效:期望表单值“正文”
【问题讨论】: