CodeIgniter Forums

Full Version: How do I upload a file with CURLRequest?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am unable to implement a curl call using the library. I'm trying to write the following command using the library:
Code:
curl -i --upload-file /Users/peter/Desktop/superneatimage.png --header "Authorization: Bearer redacted" 'https://api.linkedin.com/mediaUpload/C5522AQGTYER3k3ByHQ/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQJbrN86Zm265gAAAWemyz2pxPSgONtBiZdchrgG872QltnfYjnMdb2j3A&app=1953784&sync=0&v=beta&ut=2H-IhpbfXrRow1'
If you are interested in the documentation, here is a link. I'm trying to share an image and stuck on the upload part. This is what I have tried and I am getting all sorts of errors. Mostly bad requests but from time to time I would get an ssl error

PHP Code:
$client = \Config\Services::curlrequest([], nullnullfalse);
                                    try {
                                        $response $client->request('post'$uploadURL, [
                                        'headers' => [
                                            'Authorization' => 'Bearer ' $Social->AuthorizationToken,
                                            'X-Restli-Protocol-Version' => '2.0.0',
                                            'Content-Type' => 'multipart/form-data',
                                        ],
                                        'multipart' => [
                                            'upload-file' => new CURLFile(realpath("absolutepathtoimage.png"), "image/png""imagename.png"),
                                        ],
                                        'verify' => false
                                    
]);
                                    } catch (\CodeIgniter\HTTP\Exceptions\HTTPException $e) {
                                        var_dump($response);
                                        var_dump($e->getTrace());
                                        die();
                                    
I am inclined to just use plain curl. Perhaps this library is just not mature enough?