0

I'm trying to upload a video using Laravel and GuzzleHttp to DailyMotion. Here's my code:

$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 is a dynamically generated URL passed by DailyMotion. Upon executing the code above, I'll always get this error:

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

But I can upload video to the same upload URL using Postman, as displayed below: enter image description here

1 Answer 1

2

i don't think you need to specify content-type header guzzle will decide it automatically when you provide it a resource also the path of your video here seems problematic if video is stored at public directory you need to use public_path or respective path helper function to get its physical path below should work in guzzleHttp 6 check sending form files here 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); 
Sign up to request clarification or add additional context in comments.

1 Comment

I got this error when tried to run your code "production.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 2 passed to GuzzleHttp\Psr7\MultipartStream::addElement() must be of the type array, string given, called in /home/vagrant/Code/svc-titus/vendor/guzzlehttp/psr7/src/MultipartStream.php on line 70".. Basically the line that throws the error is 'contents' => fopen(base_path($file), 'r')

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.