Misc · Drive
Replace image
Replaces an organization's stored image file with an uploaded image and deletes the previous one. Provide the file ID, name, dimensions, file resource, and nullable thumbnail resource. The endpoint returns no content.
Permissions
Send an API key of the organization in the path, using the X-API-Key header.
Who may call it
- Callers need organization access and the
drive.editpermission. - Callers with assigned-only drive access may work only on files inside folders shared with them.
Request
Path parameters
-
organizationIdidrequired -
fileIdidrequired
Body
Content-Type: application/json
-
namestringrequired1–128 characters
-
widthintegerrequirednullable -
heightintegerrequirednullable -
fileobjectrequired2 properties
-
fileNamestringat most 128 characters
-
resourcestringrequired
-
-
thumbnailobjectrequirednullable2 properties
-
fileNamestringat most 128 characters
-
resourcestringrequired
-
Request
curl --fail-with-body --silent --show-error --max-time 30 --globoff \
--request POST 'https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/misc/drive/files/YOUR_FILE_ID/replace' \
--header 'X-API-Key: YOUR_API_KEY'const response = await fetch("https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/misc/drive/files/YOUR_FILE_ID/replace", {
method: "POST",
headers: {
"X-API-Key": "YOUR_API_KEY"
},
redirect: 'error',
signal: AbortSignal.timeout(30_000),
});
if (!response.ok) throw new Error(`campai HTTP ${response.status}`);
const text = await response.text();
const result = text ? JSON.parse(text) : null;
console.log(JSON.stringify(result, null, 2));<?php
$context = stream_context_create(['http' => [
'method' => 'POST',
'header' => [
'X-API-Key: YOUR_API_KEY',
],
'timeout' => 30,
'follow_location' => 0,
'ignore_errors' => true,
]]);
$text = @file_get_contents('https://cloud.campai.com/api/YOUR_ORGANIZATION_ID/misc/drive/files/YOUR_FILE_ID/replace', false, $context);
preg_match('/^HTTP\/\S+ (\d{3})/', $http_response_header[0] ?? '', $match);
$status = (int) ($match[1] ?? 0);
if ($text === false || $status < 200 || $status >= 300) {
throw new RuntimeException("campai HTTP $status (0 means no response)");
}
$result = $text === '' ? null : json_decode($text, true, 512, JSON_THROW_ON_ERROR);
echo json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR), PHP_EOL;
No request that worked has been recorded yet, so the body is not shown.
Response
200 Successful response
No response body is specified.
What else happens
- Updates the file's
name,width,height,file, andthumbnail. - If the file has a folder, updates
contentUpdatedAton that folder and its ancestors. - After the update, cleans up replaced storage resources.
- If the storage limit is exceeded, removes newly stored replacement resources before refusing the request.
- Updates cached drive storage usage by the change in stored bytes.
Errors
Other errors
| Status | Error | When |
|---|---|---|
| 400 | Only image files can be replaced this way | If the existing file or the replacement name is not an image, the endpoint returns HTTP 400 with routes.misc.drive.notAnImage. |
| 403 | You can only work inside folders shared with you | If assigned-only drive access does not allow work on the file's folder, the endpoint returns HTTP 403 with misc.drive.sharedFoldersOnly. |
| 404 | The file was not found | If the file is not found, the endpoint returns HTTP 404 with routes.misc.drive.noFile. |
Errors nearly every request can meet are listed under Errors.