-1

I need to make a request to box.com to upload a file with GuzzleHttp 6.

The request in cURL is:

 curl https://upload.box.com/api/2.0/files/content 
   -H "Authorization: Bearer ACCESS_TOKEN" 
   -X POST 
   -F attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}
   -F file=@myfile.jpg

See https://developer.box.com/reference#upload-a-file for reference.

Also in my case I do not have file but a file content.

1 Answers1

3

For the past 2 days I've been looking for an answer. And bingo.... 1 min after asking a question I managed to write something that works:

$this->http->request('POST', $url, [
RequestOptions::MULTIPART => [
    [
        'name'     => 'contents',
        'contents' => $file->getContent(),
        'filename' => $file->getFileName(),
    ],
    [
        'name'     => 'attributes',
        'contents' => json_encode([ 'name' => $file->getFileName(), "parent" => [ "id" => $dirId ] ]),
    ],
]]);