vendredi 8 avril 2022

Laravel Http Client - How to upload file to linkedin Assets API

I wanted to upload a file using Laravel HTTP Client, but I'm not able to understand how to work or attach media to LinkedIn. And moreover, LinkedIn API does not even give back any response after upload this becomes even harder for me to figure out where I went wrong.

But LinkedIn documentation shows an example using the curl command which I successfully achieved to upload a file and even in the postman I was able to do so by choosing the PUT method and body as a binary file.

Below is LinkedIn Doc under the "Upload the Image" section an example is given for bash.

https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/vector-asset-api?tabs=http#upload-the-image

Below is the small piece of code I'm trying to achieve upload functionality

   Http::attach('file', file_get_contents($request->file('file')), 'perfidious.jpg')
            ->withHeaders([
                'Authorization' => 'Bearer ' . $oauth2_token,
                'Content-Type' => $file->getMimeType(),
            ])->put('https://api.linkedin.com/mediaUpload/C4E22AQFyx5-WPFqU4w/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQJDUuJEebKdjgAAAYAIF2PvtGz3bIfDzdyIAomflRbj4jD-Z1lcfP-7NQ&app=201094746&sync=1&v=beta&ut=1S4fxf2p45tWc1')
            ->json();

What I know from Laravel Docs is "file_get_contents" method reads file data as a string.

https://laravel.com/docs/9.x/http-client

Please, anyone, help me guide on how to do it as I have very minimal knowledge in PHP and Laravel. Thanks!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/pbUhwtS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire