Deleting Object Tags
Function
This API is used to delete the tags of an object.
If there is no object version ID (indicated by versionId) contained in the request, you must have the DeleteObjectTagging permission. If there is an object version ID (indicated by versionId) contained in the request, you must have both the DeleteObjectTagging and DeleteObjectVersionTagging permissions. By default, only the object owner can perform this operation. The object owner can grant this permission to others by using a bucket or user policy.
OBS deletes tags from the current object version by default. You can use the versionId parameter to delete tags from any other version. If the version is a delete marker, OBS returns 404 Not Found.
Restrictions
- To delete the tags of an object, you must be the bucket owner or have the required permissions (obs:object:DeleteObjectTagging (versioning disabled) and obs:object:DeleteObjectVersionTagging (versioning enabled or suspended) granted using IAM or obs:object:DeleteObjectTagging (versioning disabled) and obs:object:DeleteObjectVersionTagging (versioning enabled or suspended) granted using a bucket policy). For details, see Introduction to OBS Access Control, IAM Custom Policies, and Configuring an Object Policy.
- The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
- This API is not available for parallel file systems.
Method
ObsClient.deleteObjectTagging(params)
Request Parameters
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| Bucket | String | Yes | Explanation: Bucket name Restrictions:
Default value: None |
| Key | String | Yes | Explanation: Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. For example, if the address for accessing the object is examplebucket.obs.ap-southeast-1.myhuaweicloud.com/folder/test.txt, the object name is folder/test.txt. Value range: The value must contain 1 to 1,024 characters. Default value: None |
| VersionId | String | No | Explanation: Object version ID Value range: The value must contain 32 characters. Default value: None |
Responses
| Parameter | Type | Description |
| Status | Number | Explanation: HTTP status code returned by the OBS server Value range: A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). For details, see Status Codes. |
| Code | String | Explanation: Error code returned by the OBS server |
| Message | String | Explanation: Error description returned by the OBS server |
| HostId | String | Explanation: Request server ID returned by the OBS server |
| RequestId | String | Explanation: Request ID returned by the OBS server |
| Id2 | String | Explanation: Request ID2 returned by the OBS server |
| Indicator | String | Explanation: Error code details returned by the OBS server |
Sample Code
This example deletes tags of object objectname.
// Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK before storing them in the configuration file or environment variables. In this example, the AK and SK are stored in environment variables. Before running the code in this example, configure environment variables AccessKeyID and SecretAccessKey.
// The front-end code does not have the process environment variable, so you need to use a module bundler like webpack to define the process variable.
// Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
const AK = process.env.AccessKeyID
const SK = process.env.SecretAccessKey
// (Optional) If you use a temporary AK and SK pair and a security token to access OBS, obtain them using environment variables.
const security_token= process.env.SecurityToken
// Set server to the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
const server = "https://obs.ap-southeast-1.myhuaweicloud.com"
// Create an ObsClient instance.
var obsClient = new ObsClient({
access_key_id: AK,
secret_access_key: SK,
server: server
});
async function deleteObjectTagging() {
try {
const params = {
Bucket: 'examplebucket',
Key: 'objectname',
// Specify an object version when versioning is enabled.
// VersionId: '',
};
// Delete object tags.
const result = await obsClient.deleteObjectTagging(params);
if (result.CommonMsg.Status <= 300) {
console.log("Delete object(%s)'s tagging successful!", params.Key);
console.log("RequestId: %s", result.CommonMsg.RequestId);
return;
};
console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
console.log("Status: %d", result.CommonMsg.Status);
console.log("Code: %s", result.CommonMsg.Code);
console.log("Message: %s", result.CommonMsg.Message);
console.log("RequestId: %s", result.CommonMsg.RequestId);
} catch (error) {
console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
console.log(error);
};
};
deleteObjectTagging() Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot