Makes a copy of a file. The name and description of the copy is provided in the JSON body of the request.
var
rest: HCkRest;
success: Boolean;
oauth2: HCkOAuth2;
jsonReq: HCkJsonObject;
sbReq: HCkStringBuilder;
sbJson: HCkStringBuilder;
json: HCkJsonObject;
kind: PWideChar;
id: PWideChar;
name: PWideChar;
mimeType: PWideChar;
teamDriveId: PWideChar;
begin
rest := CkRest_Create();
// Provide a previously obtained OAuth2 access token.
oauth2 := CkOAuth2_Create();
CkOAuth2_putAccessToken(oauth2,'OAUTH2_ACCESS_TOKEN');
CkRest_SetAuthOAuth2(rest,oauth2);
success := CkRest_Connect(rest,'www.googleapis.com',443,True,True);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
CkRest_AddQueryParam(rest,'supportsTeamDrives','true');
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
jsonReq := CkJsonObject_Create();
CkJsonObject_UpdateString(jsonReq,'name','penguins2.jpg');
CkJsonObject_UpdateString(jsonReq,'description','resized and edited by Matt');
sbReq := CkStringBuilder_Create();
CkJsonObject_EmitSb(jsonReq,sbReq);
CkRest_AddHeader(rest,'Content-Type','application/json');
sbJson := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'POST','/drive/v3/files/1R_70heIyzIAu1_u0prXbYcaIiJRVkgBl/copy',sbReq,sbJson);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
if (CkRest_getResponseStatusCode(rest) <> 200) then
begin
Memo1.Lines.Add('Received error response code: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
Memo1.Lines.Add('Response body:');
Memo1.Lines.Add(CkStringBuilder__getAsString(sbJson));
Exit;
end;
json := CkJsonObject_Create();
CkJsonObject_LoadSb(json,sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
kind := CkJsonObject__stringOf(json,'kind');
id := CkJsonObject__stringOf(json,'id');
name := CkJsonObject__stringOf(json,'name');
mimeType := CkJsonObject__stringOf(json,'mimeType');
teamDriveId := CkJsonObject__stringOf(json,'teamDriveId');
Memo1.Lines.Add('Example Completed.');
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkJsonObject_Dispose(jsonReq);
CkStringBuilder_Dispose(sbReq);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(json);
{
"name": "penguins2.jpg",
"description": "resized and edited by Matt"
}
{
"kind": "drive#file",
"id": "1xx378JF8abx17LXlRt65031J9TQkolQX",
"name": "penguins2.jpg",
"mimeType": "image/jpeg",
"teamDriveId": "0AEd3EhGff2SaUk9PVA"
}