Microsoft Graph API - 无法打开上载的文件

时间:2018-06-04 11:12:59

标签: php microsoft-graph guzzle

我正在尝试使用Microsoft Graph API上传文件。它似乎上传OK,但在尝试打开文件时,我被告知它无法打开。

这是我的PHP代码的相关部分。我使用Guzzle提出请求。

$data = file_get_contents($_FILES['foo']['tmp_name']);

$guzzle = new GuzzleHttp\Client();

$sent_options = [
    'headers' => [
        'Authorization' => 'Bearer ' . $accessToken,
        'Content-Type'  => 'text/plain'
    ],
    'form_params' => [
        base64_encode($data)
    ]
];

$guzzle->put($url, $sent_options);

1 个答案:

答案 0 :(得分:0)

好的,所以我已经解决了......对于遇到同样问题的其他人来说,这就是解决方案。

$data = file_get_contents($_FILES['foo']['tmp_name']);

$guzzle = new GuzzleHttp\Client();

$sent_options = [
    'headers' => [
        'Authorization' => 'Bearer ' . $accessToken,
        'Content-Type'  => 'text/plain'
    ],
    'body' => $data
];

$guzzle->put($url, $sent_options);