LinkedIn API V2-如何将照片上传为二进制文件

问题描述:

我在上传带有可见此处.

$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);

这是我的请求的样子.我尝试不使用type=行,但没有任何改变.我收到一个空响应,状态码为400.

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.

我正在使用第1步中的上传URL,所以我知道这应该是正确的.

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

我的请求怎么了?我正在尝试遵循他们在文档中提供的cURL示例,但是也许我的文件格式不正确?

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?

我也尝试过使post字段的file参数只是完整的文件路径,但这给出了false的响应.

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.

您应包括文件的系统路径,例如:user/myname/image.jpg. 内容类型应为应用程序/二进制

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