0

我正在将文件从一个驱动器复制到另一个驱动器。作为正文请求的一部分,我还提供了冲突行为作为重命名(也尝试了替换),但副本失败了。

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"
    }
}

复制时要通过什么来重命名/替换现有文件

4

1 回答 1

2

如果您尝试使用特殊名称重命名它,请尝试此操作。

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://docs.microsoft.com/en-us/graph/api/driveitem-copy?...

如果您想自动重命名文件,请尝试使用Instance Attributes

POST /users/{user-id}/drive/items/{item-id}/copy?@microsoft.graph.conflictBehavior=rename
Content-Type: application/json

{
  "name": "{filename}"
}

name应提供。

于 2020-11-08T18:23:23.640 回答