driveItem:copy
本文内容
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
以异步方式在新父项下或使用新名称创建一个 driveItem 副本(包括任何子项)。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Files.ReadWrite、Files.ReadWrite.All、Sites.ReadWrite.All
委派(个人 Microsoft 帐户)
Files.ReadWrite、Files.ReadWrite.All
应用程序
Files.ReadWrite.All、Sites.ReadWrite.All
HTTP 请求
POST /drives/{driveId}/items/{itemId}/copy
POST /groups/{groupId}/drive/items/{itemId}/copy
POST /me/drive/items/{item-id}/copy
POST /sites/{siteId}/drive/items/{itemId}/copy
POST /users/{userId}/drive/items/{itemId}/copy
可选的查询参数
此方法支持查询 @microsoft.graph.conflictBehavior 参数在发生冲突时自定义行为。
值
说明
失败
默认行为是报告失败。
replace
覆盖目标网站中的现有项目。
rename
重命名该项目。
注意: conflictBehavior 不受 OneDrive 支持。
请求正文
在请求正文中,提供具有以下参数的 JSON 对象。
名称
值
说明
parentReference
ItemReference
可选。引用在其中创建副本的父项。
name
string
可选。副本的新名称。如果未提供新名称,将同一名称用作原始名称。
注意: parentReference 应包括目标文件夹的 driveId 和 id 参数。
响应
返回有关如何在接受请求时监视复制操作进度 的详细信息。
示例
本示例将由 {item-id} 标识的文件复制到使用 driveId 和 id 值标识的文件夹。
该文件的新副本将被命名为 contoso plan (copy).txt。
请求
POST /me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"driveId": "6F7D00BF-FC4D-4E62-9769-6AEA81F3A21B",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
},
"name": "contoso plan (copy).txt"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var parentReference = new ItemReference
{
DriveId = "6F7D00BF-FC4D-4E62-9769-6AEA81F3A21B",
Id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
};
var name = "contoso plan (copy).txt";
await graphClient.Me.Drive.Items["{driveItem-id}"]
.Copy(name,parentReference)
.Request()
.PostAsync();
const options = {
authProvider,
};
const client = Client.init(options);
const driveItem = {
parentReference: {
driveId: '6F7D00BF-FC4D-4E62-9769-6AEA81F3A21B',
id: 'DCD0D3AD-8989-4F23-A5A2-2C086050513F'
},
name: 'contoso plan (copy).txt'
};
await client.api('/me/drive/items/{item-id}/copy')
.version('beta')
.post(driveItem);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/drive/items/{item-id}/copy"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
MSGraphItemReference *parentReference = [[MSGraphItemReference alloc] init];
[parentReference setDriveId:@"6F7D00BF-FC4D-4E62-9769-6AEA81F3A21B"];
[parentReference setId:@"DCD0D3AD-8989-4F23-A5A2-2C086050513F"];
payloadDictionary[@"parentReference"] = parentReference;
NSString *name = @"contoso plan (copy).txt";
payloadDictionary[@"name"] = name;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
ItemReference parentReference = new ItemReference();
parentReference.driveId = "6F7D00BF-FC4D-4E62-9769-6AEA81F3A21B";
parentReference.id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F";
String name = "contoso plan (copy).txt";
graphClient.me().drive().items("{item-id}")
.copy(DriveItemCopyParameterSet
.newBuilder()
.withName(name)
.withParentReference(parentReference)
.build())
.buildRequest()
.post();
响应
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/4A3407B5-88FC-4504-8B21-0AABD3412717
Location 头值提供的服务 URL 将返回复制操作的最新状态。
可以使用此信息来确定 复制何时完成 。
在许多情况下,异步执行复制操作。
来自 API 的响应将仅指示复制操作已接受或拒绝;例如,由于目标文件名已在使用中。