vendredi 4 décembre 2015

How to upload files with Guzzle (OAuth 2)

I'm trying to upload files using Guzzle HTTP client and send it to the API URL. However, I couldn't get success over this. I can use Curl however, I want to use Guzzle. I couldn't figure out where to add the uploading files with the Guzzle and how to use the attributes. Here's the relevant Curl code:

curl http://ift.tt/P5gcP4 \
  -H "Authorization: Bearer ACCESS_TOKEN" -X POST \
  -F attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}' \
  -F file=@myfile.jpg

Here's the reference API docs which I hope you'll find helpful. I'm using Laravel 5.

No matter what I do everytime I'm getting Method not allowed response. Here's the following code I'm trying:

$client = new Client();
        $sendRequest = $client->post('http://ift.tt/P5gcP4', [], [
            'request.options' => [
                'headers' => [
                    'Authorization' => 'Bearer ' . $access_token
                ]
            ],
            'file' => '/picture.jpg'
        ]);
        $sendRequest->setBody('{"attributes": {"name": "picture.jpg", "parent": {"id": "5605448193"}}}');
try {
    $response = $sendRequest->send();
    dd($response);
} catch(BadResponseException $e) {
        dd($e->getResponse());
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire