Issue
I'm stuck while converting a curl command to Laravel Http facade command.
curl -i --upload-file ~/Desktop/Myimage.jpg -H 'Authorization: Bearer Redacted' "https://www.linkedin.com/dms-uploads/C5622AQHdBDflPp0pEg/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&sync=1&v=beta&ut=1lrKqjt4fYuqw1"
I tried the Laravel command as below but the server complains 400 Bad Request
Http::attach("file_display_name", file_get_contents("path_to_file"), "file_name_with_extension")
->withHeaders([
"Authorization" => "Bearer Redacted"
])
->put("https://www.linkedin.com/dms-uploads/C5622AQHdBDflPp0pEg/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&sync=1&v=beta&ut=1lrKqjt4fYuqw1");
Appreciate your help with identifying what I'm doing wrong.
PS: Curl command works successfully.
Edit: Tried Postman as John Lobo suggested.
I've set the request method as PUT and have used form-data to set the file. I'm not sure if this is the proper way of doing it though as I'm getting 400 Bad Request
with this approach as well. Nothing else on the response body.
Solution
After some more research (thanks to ChatGPT), I found my mistake.
I wasn't setting the key for the file correctly. The key for the file needs to be file
exactly. Then it works.
Updated Laravel code:
Http::attach("file", file_get_contents("path_to_file"), "file_name_with_extension")
->withHeaders([
"Authorization" => "Bearer Redacted"
])
->put("https://www.linkedin.com/dms-uploads/C5622AQHdBDflPp0pEg/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&sync=1&v=beta&ut=1lrKqjt4fYuqw1");
Answered By - Jude F'do Answer Checked By - David Goodson (WPSolving Volunteer)