我正在将文件从一个驱动器复制到另一个驱动器。作为正文请求的一部分,我还提供冲突行为作为重命名(也尝试使用替换),但复制失败。
POST: https://graph.microsoft.com/beta/users/{user-id}/drive/items/{item-id}/copy
Body:
{
"parentReference": {"id": {folder-id-to-copy}, "driveId": {drive-id},
"@microsoft.graph.conflictBehavior": "rename"
}
执行上述命令后,正如预期的那样,我得到了 202,并在标题中查看了位置。查询监控 URL 时,我看到以下错误:
{
"@odata.context": "https://{host-name}/_api/v2.1/$metadata#drives('default')/operations/$entity",
"id": "7a0decd4-df2f-4717-8eee-b7c2cd131009",
"createdDateTime": "0001-01-01T00:00:00Z",
"lastActionDateTime": "0001-01-01T00:00:00Z",
"status": "failed",
"error": {
"code": "nameAlreadyExists",
"message": "Name already exists"
}
}
复制时要重命名/替换现有文件要传递什么
最佳答案
如果您尝试使用特殊名称重命名它,请尝试此操作。
POST /users/{user-id}/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"id": {folder-id-to-copy}, "driveId": {drive-id},
},
"name": "your_file_name (copy).txt"
}
引用这里:https://learn.microsoft.com/en-us/graph/api/driveitem-copy?...
如果您想自动重命名文件,请尝试使用 Instance Attributes .
POST /users/{user-id}/drive/items/{item-id}/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b48445b52146b464248594458444d5f054c594a5b43054844454d4742485f694e434a5d424459" rel="noreferrer noopener nofollow">[email protected]</a>=rename
Content-Type: application/json
{
"name": "{filename}"
}
应提供名称
。
关于sharepoint - 使用 MS Graph for Onedrive/Sharepoint 复制文件并重命名(如果存在),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63162465/