我試圖使用Laravel和GuzzleHttp將視頻上傳到DailyMotion。以下是我的代碼:使用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:
Client error: POST http://upload-02.sg1.dailymotion.com/upload?uuid=werewkrewrewrwer&seal=pppppppppppppppp `resulted in a 400 Bad Request response:
{"error":"invalid content range","seal":"yyyyyyyyyyyyyyyyyy"} in /home/vagrant/Code/svc-titus/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111
我試圖運行你的代碼「,當這個錯誤production.ERROR:Symfony的\分量\調試\異常\ FatalThrowableError:類型錯誤:傳遞給GuzzleHttp \ PSR7 \ MultipartStream :: addElement方法(參數2)必須是給出的字符串,在第70行調用/home/vagrant/Code/svc-titus/vendor/guzzlehttp/psr7/src/MultipartStream.php「。基本上引發錯誤的行是'contents'= > fopen(base_path($ file),'r') – imin
對不起,我的工作很糟糕。非常感謝! – imin