I have created image share upload url using "https://api.linkedin.com/v2/assets?action=registerUpload" and using that upload url i am trying to upload image to linked-in but i am getting Bad request 400 error from API, please find below code snippet,
private void UploadImageToLinkedIn(string accessToken)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
client.DefaultRequestHeaders.Add("X-Restli-Protocol-Version", "2.0.0");
byte[] imgBytes = System.IO.File.ReadAllBytes("D:\\work\\All_Photos\\1_full.jpg");
using (MultipartFormDataContent fd = new MultipartFormDataContent())
{
var fileContent = new ByteArrayContent(imgBytes);
fileContent.Headers.Add("Content-Type", "multipart/form-data");
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "1_full" };
fd.Add(fileContent);
string postingURL = "https://api.linkedin.com/mediaUpload/C4E22AQFg1jP-2n4Jog/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQLl5BnZw1Rk0wAAAWk5k9KsK.........";
var result = client.PostAsync(postingURL, fd).Result;
}
}
}
I have also tried it on postman with no luck. Can anyone help me out?