Skip to content
Start here

Put Bucket Lock Rules

client.r2.buckets.locks.update(stringbucketName, LockUpdateParams { account_id, rules, jurisdiction } params, RequestOptionsoptions?): LockUpdateResponse
PUT/accounts/{account_id}/r2/buckets/{bucket_name}/lock

Set lock rules for a bucket.

Security

API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
ParametersExpand Collapse
bucketName: string

Name of the bucket.

maxLength64
minLength3
params: LockUpdateParams { account_id, rules, jurisdiction }
account_id: string

Path param: Account ID.

maxLength32
rules?: Array<Rule>

Body param

id: string

Unique identifier for this rule.

condition: R2LockRuleAgeCondition { maxAgeSeconds, type } | R2LockRuleDateCondition { date, type } | R2LockRuleIndefiniteCondition { type }

Condition to apply a lock rule to an object for how long in seconds.

One of the following:
R2LockRuleAgeCondition { maxAgeSeconds, type }

Condition to apply a lock rule to an object for how long in seconds.

maxAgeSeconds: number
type: "Age"
R2LockRuleDateCondition { date, type }

Condition to apply a lock rule to an object until a specific date.

date: string
formatdate-time
type: "Date"
R2LockRuleIndefiniteCondition { type }

Condition to apply a lock rule indefinitely.

type: "Indefinite"
enabled: boolean

Whether or not this rule is in effect.

prefix?: string

Rule will only apply to objects/uploads in the bucket that start with the given prefix, an empty prefix can be provided to scope rule to all objects/uploads.

jurisdiction?: "default" | "eu" | "fedramp"

Header param: Jurisdiction where objects in this bucket are guaranteed to be stored.

One of the following:
"default"
"eu"
"fedramp"
ReturnsExpand Collapse
LockUpdateResponse = unknown

Put Bucket Lock Rules

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const lock = await client.r2.buckets.locks.update('example-bucket', {
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
});

console.log(lock);
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {},
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {},
  "success": true
}