I've used the curl request to upload an image which successfully worked for me.
curl -i --upload-file ~/Desktop/Myimage.jpg -H 'Authorization: Bearer Redacted' "https://api.linkedin.com/mediaUpload/C5522AQHn46pwH96hxQ/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQLKRJOn_yNw6wAAAW2T0DWnRStny4dzsNVJjlF3aN4-H3ZR9Div77kKoQ&app=1983914&sync=0&v=beta&ut=1Dnjy796bpjEY1"
I've tried using the same request with "request" package which got failed and redirected me to the "404 page not found" LinkedIn page.
Here is the code:
const options = {
headers: {
'Authorization': `Bearer ${accessToken}`,
'X-Restli-Protocol-Version': '2.0.0',
'Content-Type': 'multipart/form-data'
},
method: 'put',
url: mediaUploadUrl
}
fs.createReadStream(filePath).pipe(request(options, function(err, httpsResponse, body){
if ( err ) {
console.log('err', err);
response(callback, 400, err);
} else {
console.log(body);
response(callback, 200, { mediaUrn });
}
}));
Documentation page that I've followed: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/rich-media-shares