Microsoft graph api 带有哈希(#)的文件名未上载
我正试图使用以下代码将文件发送到OneDrive:Microsoft graph api 带有哈希(#)的文件名未上载,microsoft-graph-api,Microsoft Graph Api,我正试图使用以下代码将文件发送到OneDrive: $uri = "/me/drive/items/$folderId/children('{$fileName}')/content"; $graph = $this->graph->create($user); $client = $this->graph->createClient(); $item = $graph->createRequest("PUT", $uri) ->attachBod
$uri = "/me/drive/items/$folderId/children('{$fileName}')/content";
$graph = $this->graph->create($user);
$client = $this->graph->createClient();
$item = $graph->createRequest("PUT", $uri)
->attachBody($fileContent)
->setReturnType(Model\DriveItem::class)
->execute($client);
如果$fileName类似于Test.doc,那么这非常有效
但是由于某种原因,当文件名中有一个散列(#)时,我得到一个错误:
object(Microsoft\Graph\Model\DriveItem)#1509 (1) {
["_propDict":protected]=>
array(1) {
["error"]=>
array(3) {
["code"]=>
string(10) "BadRequest"
["message"]=>
string(36) "Bad Request - Error in query syntax."
["innerError"]=>
array(2) {
["request-id"]=>
string(36) "ff3fe15f-b1ee-4e92-8abd-2400b1c1b5cf"
["date"]=>
string(19) "2018-10-04T14:30:51"
}
}
}
是否有人可以澄清这是错误还是实际行为(即文件名中不能有#)
谢谢虽然文件名有支持,但这并不意味着产品团队第一次提供API或调整现有API,您使用的API可能没有完全调整以适应所有最新的命名规则。所以它现在应该是实际的行为,而不是bug/或者您可以将其视为不存在的特性 SharePoint开发中存在一个相关问题,虽然它们不是同一个问题,但建议是相同的,请在UserVoice上投票或提交一个新的问题。我猜您正在使用,需要转义特殊字符,如
#
因此,用%23
()替换哈希,或按如下所示使用:
$fileName = rawurlencode("Guide#.docx");
$requestUrl = "https://graph.microsoft.com/v1.0/drives/$driveId/root:/$fileName:/content";
try {
$item = $client->createRequest("PUT", $requestUrl)
->attachBody($fileContent)
->setReturnType(Model\DriveItem::class)
->execute();
} catch (\Microsoft\Graph\Exception\GraphException $ex) {
print $ex;
}