LinkedIn API V2 - How to upload photo as binary fi

2019-08-01 09:24发布

I'm having trouble with the second step of uploading a post with a photo seen here.

$post_fields = array(
    'file' => '@' . $_FILES['file-attachment']['tmp_name']
        . ';filename=' . $_FILES['file-attachment']['name']
        . ';type='     . $_FILES['file-attachment']['type']
);

$upload_response = process_curl(array(
    CURLOPT_URL => $upload_url,
    CURLOPT_HEADER => false,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_POSTFIELDS => $post_fields,
    CURLOPT_HTTPHEADER => array('Authorization: Bearer '.$token, 'x-li-format: json','Content-Type: multipart/form-data'),
), true);

This is what my request looks like. I tried without using the type= line but that didn't change anything. I'm getting an empty response and a status code of 400.

I'm using the upload URL from step 1 so I know that should be correct.

What about my request looks wrong? I'm trying to follow the cURL example they gave in the documentation, but perhaps the format of my file isn't correct?

I have also tried making the file parameter of post fields just be the full file path but that gave a response of false.

Another thing for me to mention is the file path has spaces in it.

1条回答
成全新的幸福
2楼-- · 2019-08-01 10:24

You should include the sytem path of the file eg:user/myname/image.jpg. Content type should be application/binary

查看更多
登录 后发表回答