我有一個表單,可以將視頻上傳併發送到遠程目的地。我有一個cURL請求,我想用Guzzle'翻譯'到PHP。使用Guzzle上傳文件
到目前爲止,我有這樣的:
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);
}
這是捲曲我用,想轉換爲PHP:
curl -X POST -F 'body={"name":"Test","country":"Deutschland"};type=application/json' -F '[email protected]:\Users\PROD\Downloads\617103.mp4;type= video/mp4 ' http://mydomain.de:8080/spots
所以,當我上傳的視頻,我要取代這個硬編碼
C:\ Users \ PROD \ Downloads \ 617103.mp4。
當我運行它,我得到一個錯誤:
Client error:
POST http://mydomain.de:8080/spots
resulted in a400 Bad Request
response: request body invalid: expecting form value 'body`'Client error:
POST http://mydomain.de/spots
resulted in a400 Bad Request
response: request body invalid: expecting form value 'body'