0

Create a URL for an object

by
Published Oct 17, 2025

Creates a pre-signed URL to access a single object in a bucket. Use it to share, create, or delete objects by using the appropriate HTTP method in your request body's `method` parameter. > 📘 > > You can use an outside API, such as the [Ceph Object Gateway S3 API](https://docs.ceph.com/en/latest/radosgw/s3/) for more options. > --- - __OAuth scopes__. ``` object_storage:read_write ``` [Learn more...](https://techdocs.akamai.com/linode-api/reference/get-started#oauth)

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Create a URL for an object
7
 * Creates a pre-signed URL to access a single object in a bucket. Use it to share, create, or delete objects by using the appropriate HTTP method in your request body's `method` parameter.
8

9
> 📘
10
>
11
> You can use an outside API, such as the [Ceph Object Gateway S3 API](https://docs.ceph.com/en/latest/radosgw/s3/) for more options.
12

13

14
>
15

16
---
17

18

19
- __OAuth scopes__.
20

21
    ```
22
    object_storage:read_write
23
    ```
24

25
    [Learn more...](https://techdocs.akamai.com/linode-api/reference/get-started#oauth)
26
 */
27
export async function main(
28
  auth: Linode,
29
  apiVersion: "v4" | "v4beta",
30
  regionId: string,
31
  bucket: string,
32
  body: {
33
    content_type?: string;
34
    expires_in?: number;
35
    method: string;
36
    name: string;
37
  },
38
) {
39
  const url = new URL(
40
    `https://api.linode.com/${apiVersion}/object-storage/buckets/${regionId}/${bucket}/object-url`,
41
  );
42

43
  const response = await fetch(url, {
44
    method: "POST",
45
    headers: {
46
      "Content-Type": "application/json",
47
      Authorization: "Bearer " + auth.token,
48
    },
49
    body: JSON.stringify(body),
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.json();
56
}
57