@supabase/storage-js 1.7.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -4,6 +4,142 @@ JS Client library to interact with Supabase Storage.
|
|
|
4
4
|
|
|
5
5
|
- Documentation: https://supabase.io/docs/reference/javascript/storage-createbucket
|
|
6
6
|
|
|
7
|
+
## Quick Start Guide
|
|
8
|
+
|
|
9
|
+
### Installing the module
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @supabase/storage-js
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Connecting to the storage backend
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { SupabaseStorageClient } from '@supabase/storage-js'
|
|
19
|
+
|
|
20
|
+
const STORAGE_URL = 'https://<project_ref>.supabase.co/storage/v1'
|
|
21
|
+
const SERVICE_KEY = '<service_role>' //! service key, not anon key
|
|
22
|
+
|
|
23
|
+
const storageClient = new SupabaseStorageClient(STORAGE_URL, {
|
|
24
|
+
apikey: SERVICE_KEY,
|
|
25
|
+
Authorization: `Bearer ${SERVICE_KEY}`,
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Handling resources
|
|
30
|
+
|
|
31
|
+
#### Handling Storage Buckets
|
|
32
|
+
|
|
33
|
+
- Create a new Storage bucket:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const { data, error } = await storageClient.createBucket(
|
|
37
|
+
'test_bucket', // Bucket name (must be unique)
|
|
38
|
+
{ public: false } // Bucket options
|
|
39
|
+
)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- Retrieve the details of an existing Storage bucket:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
const { data, error } = await storageClient.getBucket('test_bucket')
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- Update a new Storage bucket:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
const { data, error } = await storageClient.updateBucket(
|
|
52
|
+
'test_bucket', // Bucket name
|
|
53
|
+
{ public: false } // Bucket options
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- Remove all objects inside a single bucket:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
const { data, error } = await storageClient.emptyBucket('test_bucket')
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- Delete an existing bucket (a bucket can't be deleted with existing objects inside it):
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
const { data, error } = await storageClient.deleteBucket('test_bucket')
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- Retrieve the details of all Storage buckets within an existing project:
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
const { data, error } = await storageClient.listBuckets()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Handling Files
|
|
76
|
+
|
|
77
|
+
- Upload a file to an existing bucket:
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
const fileBody = ... // load your file here
|
|
81
|
+
|
|
82
|
+
const { data, error } = await storageClient.from('bucket').upload('path/to/file', fileBody)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
> Note: The `upload` method also accepts a map of optional parameters. For a complete list see the [Supabase API reference](https://supabase.com/docs/reference/javascript/storage-from-upload).
|
|
86
|
+
|
|
87
|
+
- Download a file from an exisiting bucket:
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
const { data, error } = await storageClient.from('bucket').download('path/to/file')
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- List all the files within a bucket:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
const { data, error } = await storageClient.from('bucket').list('folder')
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
> Note: The `list` method also accepts a map of optional parameters. For a complete list see the [Supabase API reference](https://supabase.com/docs/reference/javascript/storage-from-list).
|
|
100
|
+
|
|
101
|
+
- Replace an existing file at the specified path with a new one:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
const fileBody = ... // load your file here
|
|
105
|
+
|
|
106
|
+
const { data, error } = await storageClient
|
|
107
|
+
.from('bucket')
|
|
108
|
+
.update('path/to/file', fileBody)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
> Note: The `upload` method also accepts a map of optional parameters. For a complete list see the [Supabase API reference](https://supabase.com/docs/reference/javascript/storage-from-upload).
|
|
112
|
+
|
|
113
|
+
- Move an existing file:
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
const { data, error } = await storageClient
|
|
117
|
+
.from('bucket')
|
|
118
|
+
.move('old/path/to/file', 'new/path/to/file')
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
- Delete files within the same bucket:
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
const { data, error } = await storageClient.from('bucket').remove(['path/to/file'])
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- Create signed URL to download file without requiring permissions:
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
const expireIn = 60
|
|
131
|
+
|
|
132
|
+
const { data, error } = await storageClient
|
|
133
|
+
.from('bucket')
|
|
134
|
+
.createSignedUrl('path/to/file', expireIn)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
- Retrieve URLs for assets in public buckets:
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
const { data, error } = await storageClient.from('public-bucket').getPublicUrl('path/to/file')
|
|
141
|
+
```
|
|
142
|
+
|
|
7
143
|
## Sponsors
|
|
8
144
|
|
|
9
145
|
We are building the features of Firebase using enterprise-grade, open source products. We support existing communities wherever possible, and if the products don’t exist we build them and open source them ourselves. Thanks to these sponsors who are making the OSS ecosystem better for everyone.
|
|
@@ -10,7 +10,7 @@ export declare class StorageBucketApi {
|
|
|
10
10
|
[key: string]: string;
|
|
11
11
|
}, fetch?: Fetch);
|
|
12
12
|
/**
|
|
13
|
-
* Retrieves the details of all Storage buckets within an existing
|
|
13
|
+
* Retrieves the details of all Storage buckets within an existing project.
|
|
14
14
|
*/
|
|
15
15
|
listBuckets(): Promise<{
|
|
16
16
|
data: Bucket[] | null;
|
|
@@ -40,7 +40,7 @@ export declare class StorageBucketApi {
|
|
|
40
40
|
/**
|
|
41
41
|
* Updates a new Storage bucket
|
|
42
42
|
*
|
|
43
|
-
* @param id A unique identifier for the bucket you are
|
|
43
|
+
* @param id A unique identifier for the bucket you are updating.
|
|
44
44
|
*/
|
|
45
45
|
updateBucket(id: string, options: {
|
|
46
46
|
public: boolean;
|
|
@@ -20,7 +20,7 @@ class StorageBucketApi {
|
|
|
20
20
|
this.fetch = helpers_1.resolveFetch(fetch);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* Retrieves the details of all Storage buckets within an existing
|
|
23
|
+
* Retrieves the details of all Storage buckets within an existing project.
|
|
24
24
|
*/
|
|
25
25
|
listBuckets() {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -69,7 +69,7 @@ class StorageBucketApi {
|
|
|
69
69
|
/**
|
|
70
70
|
* Updates a new Storage bucket
|
|
71
71
|
*
|
|
72
|
-
* @param id A unique identifier for the bucket you are
|
|
72
|
+
* @param id A unique identifier for the bucket you are updating.
|
|
73
73
|
*/
|
|
74
74
|
updateBucket(id, options) {
|
|
75
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -10,7 +10,7 @@ export declare class StorageBucketApi {
|
|
|
10
10
|
[key: string]: string;
|
|
11
11
|
}, fetch?: Fetch);
|
|
12
12
|
/**
|
|
13
|
-
* Retrieves the details of all Storage buckets within an existing
|
|
13
|
+
* Retrieves the details of all Storage buckets within an existing project.
|
|
14
14
|
*/
|
|
15
15
|
listBuckets(): Promise<{
|
|
16
16
|
data: Bucket[] | null;
|
|
@@ -40,7 +40,7 @@ export declare class StorageBucketApi {
|
|
|
40
40
|
/**
|
|
41
41
|
* Updates a new Storage bucket
|
|
42
42
|
*
|
|
43
|
-
* @param id A unique identifier for the bucket you are
|
|
43
|
+
* @param id A unique identifier for the bucket you are updating.
|
|
44
44
|
*/
|
|
45
45
|
updateBucket(id: string, options: {
|
|
46
46
|
public: boolean;
|
|
@@ -17,7 +17,7 @@ export class StorageBucketApi {
|
|
|
17
17
|
this.fetch = resolveFetch(fetch);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Retrieves the details of all Storage buckets within an existing
|
|
20
|
+
* Retrieves the details of all Storage buckets within an existing project.
|
|
21
21
|
*/
|
|
22
22
|
listBuckets() {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -66,7 +66,7 @@ export class StorageBucketApi {
|
|
|
66
66
|
/**
|
|
67
67
|
* Updates a new Storage bucket
|
|
68
68
|
*
|
|
69
|
-
* @param id A unique identifier for the bucket you are
|
|
69
|
+
* @param id A unique identifier for the bucket you are updating.
|
|
70
70
|
*/
|
|
71
71
|
updateBucket(id, options) {
|
|
72
72
|
return __awaiter(this, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ export class StorageBucketApi {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Retrieves the details of all Storage buckets within an existing
|
|
18
|
+
* Retrieves the details of all Storage buckets within an existing project.
|
|
19
19
|
*/
|
|
20
20
|
async listBuckets(): Promise<{ data: Bucket[] | null; error: Error | null }> {
|
|
21
21
|
try {
|
|
@@ -66,7 +66,7 @@ export class StorageBucketApi {
|
|
|
66
66
|
/**
|
|
67
67
|
* Updates a new Storage bucket
|
|
68
68
|
*
|
|
69
|
-
* @param id A unique identifier for the bucket you are
|
|
69
|
+
* @param id A unique identifier for the bucket you are updating.
|
|
70
70
|
*/
|
|
71
71
|
async updateBucket(
|
|
72
72
|
id: string,
|