@supabase/storage-js 2.87.4-canary.2 → 2.87.4-canary.4
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 +2 -106
- package/dist/index.cjs +3019 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2601 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +2601 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2998 -0
- package/dist/index.mjs.map +1 -0
- package/dist/umd/supabase.js +1 -1
- package/package.json +21 -12
- package/src/lib/version.ts +1 -1
- package/dist/main/StorageClient.d.ts +0 -64
- package/dist/main/StorageClient.d.ts.map +0 -1
- package/dist/main/StorageClient.js +0 -74
- package/dist/main/StorageClient.js.map +0 -1
- package/dist/main/index.d.ts +0 -7
- package/dist/main/index.d.ts.map +0 -1
- package/dist/main/index.js +0 -12
- package/dist/main/index.js.map +0 -1
- package/dist/main/lib/constants.d.ts +0 -4
- package/dist/main/lib/constants.d.ts.map +0 -1
- package/dist/main/lib/constants.js +0 -8
- package/dist/main/lib/constants.js.map +0 -1
- package/dist/main/lib/errors.d.ts +0 -21
- package/dist/main/lib/errors.d.ts.map +0 -1
- package/dist/main/lib/errors.js +0 -41
- package/dist/main/lib/errors.js.map +0 -1
- package/dist/main/lib/fetch.d.ts +0 -16
- package/dist/main/lib/fetch.d.ts.map +0 -1
- package/dist/main/lib/fetch.js +0 -95
- package/dist/main/lib/fetch.js.map +0 -1
- package/dist/main/lib/helpers.d.ts +0 -28
- package/dist/main/lib/helpers.d.ts.map +0 -1
- package/dist/main/lib/helpers.js +0 -87
- package/dist/main/lib/helpers.js.map +0 -1
- package/dist/main/lib/index.d.ts +0 -6
- package/dist/main/lib/index.d.ts.map +0 -1
- package/dist/main/lib/index.js +0 -9
- package/dist/main/lib/index.js.map +0 -1
- package/dist/main/lib/types.d.ts +0 -226
- package/dist/main/lib/types.d.ts.map +0 -1
- package/dist/main/lib/types.js +0 -3
- package/dist/main/lib/types.js.map +0 -1
- package/dist/main/lib/vectors/StorageVectorsClient.d.ts +0 -505
- package/dist/main/lib/vectors/StorageVectorsClient.d.ts.map +0 -1
- package/dist/main/lib/vectors/StorageVectorsClient.js +0 -582
- package/dist/main/lib/vectors/StorageVectorsClient.js.map +0 -1
- package/dist/main/lib/vectors/VectorBucketApi.d.ts +0 -32
- package/dist/main/lib/vectors/VectorBucketApi.d.ts.map +0 -1
- package/dist/main/lib/vectors/VectorBucketApi.js +0 -102
- package/dist/main/lib/vectors/VectorBucketApi.js.map +0 -1
- package/dist/main/lib/vectors/VectorDataApi.d.ts +0 -32
- package/dist/main/lib/vectors/VectorDataApi.d.ts.map +0 -1
- package/dist/main/lib/vectors/VectorDataApi.js +0 -147
- package/dist/main/lib/vectors/VectorDataApi.js.map +0 -1
- package/dist/main/lib/vectors/VectorIndexApi.d.ts +0 -47
- package/dist/main/lib/vectors/VectorIndexApi.d.ts.map +0 -1
- package/dist/main/lib/vectors/VectorIndexApi.js +0 -104
- package/dist/main/lib/vectors/VectorIndexApi.js.map +0 -1
- package/dist/main/lib/vectors/constants.d.ts +0 -5
- package/dist/main/lib/vectors/constants.d.ts.map +0 -1
- package/dist/main/lib/vectors/constants.js +0 -9
- package/dist/main/lib/vectors/constants.js.map +0 -1
- package/dist/main/lib/vectors/errors.d.ts +0 -55
- package/dist/main/lib/vectors/errors.d.ts.map +0 -1
- package/dist/main/lib/vectors/errors.js +0 -76
- package/dist/main/lib/vectors/errors.js.map +0 -1
- package/dist/main/lib/vectors/fetch.d.ts +0 -57
- package/dist/main/lib/vectors/fetch.d.ts.map +0 -1
- package/dist/main/lib/vectors/fetch.js +0 -167
- package/dist/main/lib/vectors/fetch.js.map +0 -1
- package/dist/main/lib/vectors/helpers.d.ts +0 -46
- package/dist/main/lib/vectors/helpers.d.ts.map +0 -1
- package/dist/main/lib/vectors/helpers.js +0 -74
- package/dist/main/lib/vectors/helpers.js.map +0 -1
- package/dist/main/lib/vectors/index.d.ts +0 -11
- package/dist/main/lib/vectors/index.d.ts.map +0 -1
- package/dist/main/lib/vectors/index.js +0 -31
- package/dist/main/lib/vectors/index.js.map +0 -1
- package/dist/main/lib/vectors/types.d.ts +0 -279
- package/dist/main/lib/vectors/types.d.ts.map +0 -1
- package/dist/main/lib/vectors/types.js +0 -3
- package/dist/main/lib/vectors/types.js.map +0 -1
- package/dist/main/lib/version.d.ts +0 -2
- package/dist/main/lib/version.d.ts.map +0 -1
- package/dist/main/lib/version.js +0 -11
- package/dist/main/lib/version.js.map +0 -1
- package/dist/main/packages/BlobDownloadBuilder.d.ts +0 -16
- package/dist/main/packages/BlobDownloadBuilder.d.ts.map +0 -1
- package/dist/main/packages/BlobDownloadBuilder.js +0 -55
- package/dist/main/packages/BlobDownloadBuilder.js.map +0 -1
- package/dist/main/packages/StorageAnalyticsClient.d.ts +0 -324
- package/dist/main/packages/StorageAnalyticsClient.d.ts.map +0 -1
- package/dist/main/packages/StorageAnalyticsClient.js +0 -395
- package/dist/main/packages/StorageAnalyticsClient.js.map +0 -1
- package/dist/main/packages/StorageBucketApi.d.ts +0 -266
- package/dist/main/packages/StorageBucketApi.d.ts.map +0 -1
- package/dist/main/packages/StorageBucketApi.js +0 -362
- package/dist/main/packages/StorageBucketApi.js.map +0 -1
- package/dist/main/packages/StorageFileApi.d.ts +0 -680
- package/dist/main/packages/StorageFileApi.d.ts.map +0 -1
- package/dist/main/packages/StorageFileApi.js +0 -1002
- package/dist/main/packages/StorageFileApi.js.map +0 -1
- package/dist/main/packages/StreamDownloadBuilder.d.ts +0 -9
- package/dist/main/packages/StreamDownloadBuilder.d.ts.map +0 -1
- package/dist/main/packages/StreamDownloadBuilder.js +0 -35
- package/dist/main/packages/StreamDownloadBuilder.js.map +0 -1
- package/dist/module/StorageClient.d.ts +0 -64
- package/dist/module/StorageClient.d.ts.map +0 -1
- package/dist/module/StorageClient.js +0 -69
- package/dist/module/StorageClient.js.map +0 -1
- package/dist/module/index.d.ts +0 -7
- package/dist/module/index.d.ts.map +0 -1
- package/dist/module/index.js +0 -6
- package/dist/module/index.js.map +0 -1
- package/dist/module/lib/constants.d.ts +0 -4
- package/dist/module/lib/constants.d.ts.map +0 -1
- package/dist/module/lib/constants.js +0 -5
- package/dist/module/lib/constants.js.map +0 -1
- package/dist/module/lib/errors.d.ts +0 -21
- package/dist/module/lib/errors.d.ts.map +0 -1
- package/dist/module/lib/errors.js +0 -34
- package/dist/module/lib/errors.js.map +0 -1
- package/dist/module/lib/fetch.d.ts +0 -16
- package/dist/module/lib/fetch.d.ts.map +0 -1
- package/dist/module/lib/fetch.js +0 -88
- package/dist/module/lib/fetch.js.map +0 -1
- package/dist/module/lib/helpers.d.ts +0 -28
- package/dist/module/lib/helpers.d.ts.map +0 -1
- package/dist/module/lib/helpers.js +0 -79
- package/dist/module/lib/helpers.js.map +0 -1
- package/dist/module/lib/index.d.ts +0 -6
- package/dist/module/lib/index.d.ts.map +0 -1
- package/dist/module/lib/index.js +0 -6
- package/dist/module/lib/index.js.map +0 -1
- package/dist/module/lib/types.d.ts +0 -226
- package/dist/module/lib/types.d.ts.map +0 -1
- package/dist/module/lib/types.js +0 -2
- package/dist/module/lib/types.js.map +0 -1
- package/dist/module/lib/vectors/StorageVectorsClient.d.ts +0 -505
- package/dist/module/lib/vectors/StorageVectorsClient.d.ts.map +0 -1
- package/dist/module/lib/vectors/StorageVectorsClient.js +0 -576
- package/dist/module/lib/vectors/StorageVectorsClient.js.map +0 -1
- package/dist/module/lib/vectors/VectorBucketApi.d.ts +0 -32
- package/dist/module/lib/vectors/VectorBucketApi.d.ts.map +0 -1
- package/dist/module/lib/vectors/VectorBucketApi.js +0 -99
- package/dist/module/lib/vectors/VectorBucketApi.js.map +0 -1
- package/dist/module/lib/vectors/VectorDataApi.d.ts +0 -32
- package/dist/module/lib/vectors/VectorDataApi.d.ts.map +0 -1
- package/dist/module/lib/vectors/VectorDataApi.js +0 -144
- package/dist/module/lib/vectors/VectorDataApi.js.map +0 -1
- package/dist/module/lib/vectors/VectorIndexApi.d.ts +0 -47
- package/dist/module/lib/vectors/VectorIndexApi.d.ts.map +0 -1
- package/dist/module/lib/vectors/VectorIndexApi.js +0 -101
- package/dist/module/lib/vectors/VectorIndexApi.js.map +0 -1
- package/dist/module/lib/vectors/constants.d.ts +0 -5
- package/dist/module/lib/vectors/constants.d.ts.map +0 -1
- package/dist/module/lib/vectors/constants.js +0 -6
- package/dist/module/lib/vectors/constants.js.map +0 -1
- package/dist/module/lib/vectors/errors.d.ts +0 -55
- package/dist/module/lib/vectors/errors.d.ts.map +0 -1
- package/dist/module/lib/vectors/errors.js +0 -69
- package/dist/module/lib/vectors/errors.js.map +0 -1
- package/dist/module/lib/vectors/fetch.d.ts +0 -57
- package/dist/module/lib/vectors/fetch.d.ts.map +0 -1
- package/dist/module/lib/vectors/fetch.js +0 -161
- package/dist/module/lib/vectors/fetch.js.map +0 -1
- package/dist/module/lib/vectors/helpers.d.ts +0 -46
- package/dist/module/lib/vectors/helpers.d.ts.map +0 -1
- package/dist/module/lib/vectors/helpers.js +0 -66
- package/dist/module/lib/vectors/helpers.js.map +0 -1
- package/dist/module/lib/vectors/index.d.ts +0 -11
- package/dist/module/lib/vectors/index.d.ts.map +0 -1
- package/dist/module/lib/vectors/index.js +0 -11
- package/dist/module/lib/vectors/index.js.map +0 -1
- package/dist/module/lib/vectors/types.d.ts +0 -279
- package/dist/module/lib/vectors/types.d.ts.map +0 -1
- package/dist/module/lib/vectors/types.js +0 -2
- package/dist/module/lib/vectors/types.js.map +0 -1
- package/dist/module/lib/version.d.ts +0 -2
- package/dist/module/lib/version.d.ts.map +0 -1
- package/dist/module/lib/version.js +0 -8
- package/dist/module/lib/version.js.map +0 -1
- package/dist/module/packages/BlobDownloadBuilder.d.ts +0 -16
- package/dist/module/packages/BlobDownloadBuilder.d.ts.map +0 -1
- package/dist/module/packages/BlobDownloadBuilder.js +0 -53
- package/dist/module/packages/BlobDownloadBuilder.js.map +0 -1
- package/dist/module/packages/StorageAnalyticsClient.d.ts +0 -324
- package/dist/module/packages/StorageAnalyticsClient.d.ts.map +0 -1
- package/dist/module/packages/StorageAnalyticsClient.js +0 -392
- package/dist/module/packages/StorageAnalyticsClient.js.map +0 -1
- package/dist/module/packages/StorageBucketApi.d.ts +0 -266
- package/dist/module/packages/StorageBucketApi.d.ts.map +0 -1
- package/dist/module/packages/StorageBucketApi.js +0 -359
- package/dist/module/packages/StorageBucketApi.js.map +0 -1
- package/dist/module/packages/StorageFileApi.d.ts +0 -680
- package/dist/module/packages/StorageFileApi.d.ts.map +0 -1
- package/dist/module/packages/StorageFileApi.js +0 -999
- package/dist/module/packages/StorageFileApi.js.map +0 -1
- package/dist/module/packages/StreamDownloadBuilder.d.ts +0 -9
- package/dist/module/packages/StreamDownloadBuilder.d.ts.map +0 -1
- package/dist/module/packages/StreamDownloadBuilder.js +0 -32
- package/dist/module/packages/StreamDownloadBuilder.js.map +0 -1
- package/dist/tsconfig.module.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,1002 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const errors_1 = require("../lib/errors");
|
|
5
|
-
const fetch_1 = require("../lib/fetch");
|
|
6
|
-
const helpers_1 = require("../lib/helpers");
|
|
7
|
-
const BlobDownloadBuilder_1 = tslib_1.__importDefault(require("./BlobDownloadBuilder"));
|
|
8
|
-
const DEFAULT_SEARCH_OPTIONS = {
|
|
9
|
-
limit: 100,
|
|
10
|
-
offset: 0,
|
|
11
|
-
sortBy: {
|
|
12
|
-
column: 'name',
|
|
13
|
-
order: 'asc',
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
const DEFAULT_FILE_OPTIONS = {
|
|
17
|
-
cacheControl: '3600',
|
|
18
|
-
contentType: 'text/plain;charset=UTF-8',
|
|
19
|
-
upsert: false,
|
|
20
|
-
};
|
|
21
|
-
class StorageFileApi {
|
|
22
|
-
constructor(url, headers = {}, bucketId, fetch) {
|
|
23
|
-
this.shouldThrowOnError = false;
|
|
24
|
-
this.url = url;
|
|
25
|
-
this.headers = headers;
|
|
26
|
-
this.bucketId = bucketId;
|
|
27
|
-
this.fetch = (0, helpers_1.resolveFetch)(fetch);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Enable throwing errors instead of returning them.
|
|
31
|
-
*
|
|
32
|
-
* @category File Buckets
|
|
33
|
-
*/
|
|
34
|
-
throwOnError() {
|
|
35
|
-
this.shouldThrowOnError = true;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one.
|
|
40
|
-
*
|
|
41
|
-
* @param method HTTP method.
|
|
42
|
-
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
43
|
-
* @param fileBody The body of the file to be stored in the bucket.
|
|
44
|
-
*/
|
|
45
|
-
uploadOrUpdate(method, path, fileBody, fileOptions) {
|
|
46
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
try {
|
|
48
|
-
let body;
|
|
49
|
-
const options = Object.assign(Object.assign({}, DEFAULT_FILE_OPTIONS), fileOptions);
|
|
50
|
-
let headers = Object.assign(Object.assign({}, this.headers), (method === 'POST' && { 'x-upsert': String(options.upsert) }));
|
|
51
|
-
const metadata = options.metadata;
|
|
52
|
-
if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {
|
|
53
|
-
body = new FormData();
|
|
54
|
-
body.append('cacheControl', options.cacheControl);
|
|
55
|
-
if (metadata) {
|
|
56
|
-
body.append('metadata', this.encodeMetadata(metadata));
|
|
57
|
-
}
|
|
58
|
-
body.append('', fileBody);
|
|
59
|
-
}
|
|
60
|
-
else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
|
|
61
|
-
body = fileBody;
|
|
62
|
-
// Only append if not already present
|
|
63
|
-
if (!body.has('cacheControl')) {
|
|
64
|
-
body.append('cacheControl', options.cacheControl);
|
|
65
|
-
}
|
|
66
|
-
if (metadata && !body.has('metadata')) {
|
|
67
|
-
body.append('metadata', this.encodeMetadata(metadata));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
body = fileBody;
|
|
72
|
-
headers['cache-control'] = `max-age=${options.cacheControl}`;
|
|
73
|
-
headers['content-type'] = options.contentType;
|
|
74
|
-
if (metadata) {
|
|
75
|
-
headers['x-metadata'] = this.toBase64(this.encodeMetadata(metadata));
|
|
76
|
-
}
|
|
77
|
-
// Node.js streams require duplex option for fetch in Node 20+
|
|
78
|
-
// Check for both web ReadableStream and Node.js streams
|
|
79
|
-
const isStream = (typeof ReadableStream !== 'undefined' && body instanceof ReadableStream) ||
|
|
80
|
-
(body && typeof body === 'object' && 'pipe' in body && typeof body.pipe === 'function');
|
|
81
|
-
if (isStream && !options.duplex) {
|
|
82
|
-
options.duplex = 'half';
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (fileOptions === null || fileOptions === void 0 ? void 0 : fileOptions.headers) {
|
|
86
|
-
headers = Object.assign(Object.assign({}, headers), fileOptions.headers);
|
|
87
|
-
}
|
|
88
|
-
const cleanPath = this._removeEmptyFolders(path);
|
|
89
|
-
const _path = this._getFinalPath(cleanPath);
|
|
90
|
-
const data = yield (method == 'PUT' ? fetch_1.put : fetch_1.post)(this.fetch, `${this.url}/object/${_path}`, body, Object.assign({ headers }, ((options === null || options === void 0 ? void 0 : options.duplex) ? { duplex: options.duplex } : {})));
|
|
91
|
-
return {
|
|
92
|
-
data: { path: cleanPath, id: data.Id, fullPath: data.Key },
|
|
93
|
-
error: null,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
if (this.shouldThrowOnError) {
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
101
|
-
return { data: null, error };
|
|
102
|
-
}
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Uploads a file to an existing bucket.
|
|
109
|
-
*
|
|
110
|
-
* @category File Buckets
|
|
111
|
-
* @param path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
112
|
-
* @param fileBody The body of the file to be stored in the bucket.
|
|
113
|
-
* @param fileOptions Optional file upload options including cacheControl, contentType, upsert, and metadata.
|
|
114
|
-
* @returns Promise with response containing file path, id, and fullPath or error
|
|
115
|
-
*
|
|
116
|
-
* @example Upload file
|
|
117
|
-
* ```js
|
|
118
|
-
* const avatarFile = event.target.files[0]
|
|
119
|
-
* const { data, error } = await supabase
|
|
120
|
-
* .storage
|
|
121
|
-
* .from('avatars')
|
|
122
|
-
* .upload('public/avatar1.png', avatarFile, {
|
|
123
|
-
* cacheControl: '3600',
|
|
124
|
-
* upsert: false
|
|
125
|
-
* })
|
|
126
|
-
* ```
|
|
127
|
-
*
|
|
128
|
-
* Response:
|
|
129
|
-
* ```json
|
|
130
|
-
* {
|
|
131
|
-
* "data": {
|
|
132
|
-
* "path": "public/avatar1.png",
|
|
133
|
-
* "fullPath": "avatars/public/avatar1.png"
|
|
134
|
-
* },
|
|
135
|
-
* "error": null
|
|
136
|
-
* }
|
|
137
|
-
* ```
|
|
138
|
-
*
|
|
139
|
-
* @example Upload file using `ArrayBuffer` from base64 file data
|
|
140
|
-
* ```js
|
|
141
|
-
* import { decode } from 'base64-arraybuffer'
|
|
142
|
-
*
|
|
143
|
-
* const { data, error } = await supabase
|
|
144
|
-
* .storage
|
|
145
|
-
* .from('avatars')
|
|
146
|
-
* .upload('public/avatar1.png', decode('base64FileData'), {
|
|
147
|
-
* contentType: 'image/png'
|
|
148
|
-
* })
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
upload(path, fileBody, fileOptions) {
|
|
152
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
return this.uploadOrUpdate('POST', path, fileBody, fileOptions);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Upload a file with a token generated from `createSignedUploadUrl`.
|
|
158
|
-
*
|
|
159
|
-
* @category File Buckets
|
|
160
|
-
* @param path The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
161
|
-
* @param token The token generated from `createSignedUploadUrl`
|
|
162
|
-
* @param fileBody The body of the file to be stored in the bucket.
|
|
163
|
-
* @param fileOptions HTTP headers (cacheControl, contentType, etc.).
|
|
164
|
-
* **Note:** The `upsert` option has no effect here. To enable upsert behavior,
|
|
165
|
-
* pass `{ upsert: true }` when calling `createSignedUploadUrl()` instead.
|
|
166
|
-
* @returns Promise with response containing file path and fullPath or error
|
|
167
|
-
*
|
|
168
|
-
* @example Upload to a signed URL
|
|
169
|
-
* ```js
|
|
170
|
-
* const { data, error } = await supabase
|
|
171
|
-
* .storage
|
|
172
|
-
* .from('avatars')
|
|
173
|
-
* .uploadToSignedUrl('folder/cat.jpg', 'token-from-createSignedUploadUrl', file)
|
|
174
|
-
* ```
|
|
175
|
-
*
|
|
176
|
-
* Response:
|
|
177
|
-
* ```json
|
|
178
|
-
* {
|
|
179
|
-
* "data": {
|
|
180
|
-
* "path": "folder/cat.jpg",
|
|
181
|
-
* "fullPath": "avatars/folder/cat.jpg"
|
|
182
|
-
* },
|
|
183
|
-
* "error": null
|
|
184
|
-
* }
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
|
-
uploadToSignedUrl(path, token, fileBody, fileOptions) {
|
|
188
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
const cleanPath = this._removeEmptyFolders(path);
|
|
190
|
-
const _path = this._getFinalPath(cleanPath);
|
|
191
|
-
const url = new URL(this.url + `/object/upload/sign/${_path}`);
|
|
192
|
-
url.searchParams.set('token', token);
|
|
193
|
-
try {
|
|
194
|
-
let body;
|
|
195
|
-
const options = Object.assign({ upsert: DEFAULT_FILE_OPTIONS.upsert }, fileOptions);
|
|
196
|
-
const headers = Object.assign(Object.assign({}, this.headers), { 'x-upsert': String(options.upsert) });
|
|
197
|
-
if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {
|
|
198
|
-
body = new FormData();
|
|
199
|
-
body.append('cacheControl', options.cacheControl);
|
|
200
|
-
body.append('', fileBody);
|
|
201
|
-
}
|
|
202
|
-
else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
|
|
203
|
-
body = fileBody;
|
|
204
|
-
body.append('cacheControl', options.cacheControl);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
body = fileBody;
|
|
208
|
-
headers['cache-control'] = `max-age=${options.cacheControl}`;
|
|
209
|
-
headers['content-type'] = options.contentType;
|
|
210
|
-
}
|
|
211
|
-
const data = yield (0, fetch_1.put)(this.fetch, url.toString(), body, { headers });
|
|
212
|
-
return {
|
|
213
|
-
data: { path: cleanPath, fullPath: data.Key },
|
|
214
|
-
error: null,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
if (this.shouldThrowOnError) {
|
|
219
|
-
throw error;
|
|
220
|
-
}
|
|
221
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
222
|
-
return { data: null, error };
|
|
223
|
-
}
|
|
224
|
-
throw error;
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Creates a signed upload URL.
|
|
230
|
-
* Signed upload URLs can be used to upload files to the bucket without further authentication.
|
|
231
|
-
* They are valid for 2 hours.
|
|
232
|
-
*
|
|
233
|
-
* @category File Buckets
|
|
234
|
-
* @param path The file path, including the current file name. For example `folder/image.png`.
|
|
235
|
-
* @param options.upsert If set to true, allows the file to be overwritten if it already exists.
|
|
236
|
-
* @returns Promise with response containing signed upload URL, token, and path or error
|
|
237
|
-
*
|
|
238
|
-
* @example Create Signed Upload URL
|
|
239
|
-
* ```js
|
|
240
|
-
* const { data, error } = await supabase
|
|
241
|
-
* .storage
|
|
242
|
-
* .from('avatars')
|
|
243
|
-
* .createSignedUploadUrl('folder/cat.jpg')
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
* Response:
|
|
247
|
-
* ```json
|
|
248
|
-
* {
|
|
249
|
-
* "data": {
|
|
250
|
-
* "signedUrl": "https://example.supabase.co/storage/v1/object/upload/sign/avatars/folder/cat.jpg?token=<TOKEN>",
|
|
251
|
-
* "path": "folder/cat.jpg",
|
|
252
|
-
* "token": "<TOKEN>"
|
|
253
|
-
* },
|
|
254
|
-
* "error": null
|
|
255
|
-
* }
|
|
256
|
-
* ```
|
|
257
|
-
*/
|
|
258
|
-
createSignedUploadUrl(path, options) {
|
|
259
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
260
|
-
try {
|
|
261
|
-
let _path = this._getFinalPath(path);
|
|
262
|
-
const headers = Object.assign({}, this.headers);
|
|
263
|
-
if (options === null || options === void 0 ? void 0 : options.upsert) {
|
|
264
|
-
headers['x-upsert'] = 'true';
|
|
265
|
-
}
|
|
266
|
-
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/object/upload/sign/${_path}`, {}, { headers });
|
|
267
|
-
const url = new URL(this.url + data.url);
|
|
268
|
-
const token = url.searchParams.get('token');
|
|
269
|
-
if (!token) {
|
|
270
|
-
throw new errors_1.StorageError('No token returned by API');
|
|
271
|
-
}
|
|
272
|
-
return { data: { signedUrl: url.toString(), path, token }, error: null };
|
|
273
|
-
}
|
|
274
|
-
catch (error) {
|
|
275
|
-
if (this.shouldThrowOnError) {
|
|
276
|
-
throw error;
|
|
277
|
-
}
|
|
278
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
279
|
-
return { data: null, error };
|
|
280
|
-
}
|
|
281
|
-
throw error;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Replaces an existing file at the specified path with a new one.
|
|
287
|
-
*
|
|
288
|
-
* @category File Buckets
|
|
289
|
-
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to update.
|
|
290
|
-
* @param fileBody The body of the file to be stored in the bucket.
|
|
291
|
-
* @param fileOptions Optional file upload options including cacheControl, contentType, upsert, and metadata.
|
|
292
|
-
* @returns Promise with response containing file path, id, and fullPath or error
|
|
293
|
-
*
|
|
294
|
-
* @example Update file
|
|
295
|
-
* ```js
|
|
296
|
-
* const avatarFile = event.target.files[0]
|
|
297
|
-
* const { data, error } = await supabase
|
|
298
|
-
* .storage
|
|
299
|
-
* .from('avatars')
|
|
300
|
-
* .update('public/avatar1.png', avatarFile, {
|
|
301
|
-
* cacheControl: '3600',
|
|
302
|
-
* upsert: true
|
|
303
|
-
* })
|
|
304
|
-
* ```
|
|
305
|
-
*
|
|
306
|
-
* Response:
|
|
307
|
-
* ```json
|
|
308
|
-
* {
|
|
309
|
-
* "data": {
|
|
310
|
-
* "path": "public/avatar1.png",
|
|
311
|
-
* "fullPath": "avatars/public/avatar1.png"
|
|
312
|
-
* },
|
|
313
|
-
* "error": null
|
|
314
|
-
* }
|
|
315
|
-
* ```
|
|
316
|
-
*
|
|
317
|
-
* @example Update file using `ArrayBuffer` from base64 file data
|
|
318
|
-
* ```js
|
|
319
|
-
* import {decode} from 'base64-arraybuffer'
|
|
320
|
-
*
|
|
321
|
-
* const { data, error } = await supabase
|
|
322
|
-
* .storage
|
|
323
|
-
* .from('avatars')
|
|
324
|
-
* .update('public/avatar1.png', decode('base64FileData'), {
|
|
325
|
-
* contentType: 'image/png'
|
|
326
|
-
* })
|
|
327
|
-
* ```
|
|
328
|
-
*/
|
|
329
|
-
update(path, fileBody, fileOptions) {
|
|
330
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
331
|
-
return this.uploadOrUpdate('PUT', path, fileBody, fileOptions);
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Moves an existing file to a new path in the same bucket.
|
|
336
|
-
*
|
|
337
|
-
* @category File Buckets
|
|
338
|
-
* @param fromPath The original file path, including the current file name. For example `folder/image.png`.
|
|
339
|
-
* @param toPath The new file path, including the new file name. For example `folder/image-new.png`.
|
|
340
|
-
* @param options The destination options.
|
|
341
|
-
* @returns Promise with response containing success message or error
|
|
342
|
-
*
|
|
343
|
-
* @example Move file
|
|
344
|
-
* ```js
|
|
345
|
-
* const { data, error } = await supabase
|
|
346
|
-
* .storage
|
|
347
|
-
* .from('avatars')
|
|
348
|
-
* .move('public/avatar1.png', 'private/avatar2.png')
|
|
349
|
-
* ```
|
|
350
|
-
*
|
|
351
|
-
* Response:
|
|
352
|
-
* ```json
|
|
353
|
-
* {
|
|
354
|
-
* "data": {
|
|
355
|
-
* "message": "Successfully moved"
|
|
356
|
-
* },
|
|
357
|
-
* "error": null
|
|
358
|
-
* }
|
|
359
|
-
* ```
|
|
360
|
-
*/
|
|
361
|
-
move(fromPath, toPath, options) {
|
|
362
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
363
|
-
try {
|
|
364
|
-
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/object/move`, {
|
|
365
|
-
bucketId: this.bucketId,
|
|
366
|
-
sourceKey: fromPath,
|
|
367
|
-
destinationKey: toPath,
|
|
368
|
-
destinationBucket: options === null || options === void 0 ? void 0 : options.destinationBucket,
|
|
369
|
-
}, { headers: this.headers });
|
|
370
|
-
return { data, error: null };
|
|
371
|
-
}
|
|
372
|
-
catch (error) {
|
|
373
|
-
if (this.shouldThrowOnError) {
|
|
374
|
-
throw error;
|
|
375
|
-
}
|
|
376
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
377
|
-
return { data: null, error };
|
|
378
|
-
}
|
|
379
|
-
throw error;
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Copies an existing file to a new path in the same bucket.
|
|
385
|
-
*
|
|
386
|
-
* @category File Buckets
|
|
387
|
-
* @param fromPath The original file path, including the current file name. For example `folder/image.png`.
|
|
388
|
-
* @param toPath The new file path, including the new file name. For example `folder/image-copy.png`.
|
|
389
|
-
* @param options The destination options.
|
|
390
|
-
* @returns Promise with response containing copied file path or error
|
|
391
|
-
*
|
|
392
|
-
* @example Copy file
|
|
393
|
-
* ```js
|
|
394
|
-
* const { data, error } = await supabase
|
|
395
|
-
* .storage
|
|
396
|
-
* .from('avatars')
|
|
397
|
-
* .copy('public/avatar1.png', 'private/avatar2.png')
|
|
398
|
-
* ```
|
|
399
|
-
*
|
|
400
|
-
* Response:
|
|
401
|
-
* ```json
|
|
402
|
-
* {
|
|
403
|
-
* "data": {
|
|
404
|
-
* "path": "avatars/private/avatar2.png"
|
|
405
|
-
* },
|
|
406
|
-
* "error": null
|
|
407
|
-
* }
|
|
408
|
-
* ```
|
|
409
|
-
*/
|
|
410
|
-
copy(fromPath, toPath, options) {
|
|
411
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
412
|
-
try {
|
|
413
|
-
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/object/copy`, {
|
|
414
|
-
bucketId: this.bucketId,
|
|
415
|
-
sourceKey: fromPath,
|
|
416
|
-
destinationKey: toPath,
|
|
417
|
-
destinationBucket: options === null || options === void 0 ? void 0 : options.destinationBucket,
|
|
418
|
-
}, { headers: this.headers });
|
|
419
|
-
return { data: { path: data.Key }, error: null };
|
|
420
|
-
}
|
|
421
|
-
catch (error) {
|
|
422
|
-
if (this.shouldThrowOnError) {
|
|
423
|
-
throw error;
|
|
424
|
-
}
|
|
425
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
426
|
-
return { data: null, error };
|
|
427
|
-
}
|
|
428
|
-
throw error;
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Creates a signed URL. Use a signed URL to share a file for a fixed amount of time.
|
|
434
|
-
*
|
|
435
|
-
* @category File Buckets
|
|
436
|
-
* @param path The file path, including the current file name. For example `folder/image.png`.
|
|
437
|
-
* @param expiresIn The number of seconds until the signed URL expires. For example, `60` for a URL which is valid for one minute.
|
|
438
|
-
* @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
|
|
439
|
-
* @param options.transform Transform the asset before serving it to the client.
|
|
440
|
-
* @returns Promise with response containing signed URL or error
|
|
441
|
-
*
|
|
442
|
-
* @example Create Signed URL
|
|
443
|
-
* ```js
|
|
444
|
-
* const { data, error } = await supabase
|
|
445
|
-
* .storage
|
|
446
|
-
* .from('avatars')
|
|
447
|
-
* .createSignedUrl('folder/avatar1.png', 60)
|
|
448
|
-
* ```
|
|
449
|
-
*
|
|
450
|
-
* Response:
|
|
451
|
-
* ```json
|
|
452
|
-
* {
|
|
453
|
-
* "data": {
|
|
454
|
-
* "signedUrl": "https://example.supabase.co/storage/v1/object/sign/avatars/folder/avatar1.png?token=<TOKEN>"
|
|
455
|
-
* },
|
|
456
|
-
* "error": null
|
|
457
|
-
* }
|
|
458
|
-
* ```
|
|
459
|
-
*
|
|
460
|
-
* @example Create a signed URL for an asset with transformations
|
|
461
|
-
* ```js
|
|
462
|
-
* const { data } = await supabase
|
|
463
|
-
* .storage
|
|
464
|
-
* .from('avatars')
|
|
465
|
-
* .createSignedUrl('folder/avatar1.png', 60, {
|
|
466
|
-
* transform: {
|
|
467
|
-
* width: 100,
|
|
468
|
-
* height: 100,
|
|
469
|
-
* }
|
|
470
|
-
* })
|
|
471
|
-
* ```
|
|
472
|
-
*
|
|
473
|
-
* @example Create a signed URL which triggers the download of the asset
|
|
474
|
-
* ```js
|
|
475
|
-
* const { data } = await supabase
|
|
476
|
-
* .storage
|
|
477
|
-
* .from('avatars')
|
|
478
|
-
* .createSignedUrl('folder/avatar1.png', 60, {
|
|
479
|
-
* download: true,
|
|
480
|
-
* })
|
|
481
|
-
* ```
|
|
482
|
-
*/
|
|
483
|
-
createSignedUrl(path, expiresIn, options) {
|
|
484
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
485
|
-
try {
|
|
486
|
-
let _path = this._getFinalPath(path);
|
|
487
|
-
let data = yield (0, fetch_1.post)(this.fetch, `${this.url}/object/sign/${_path}`, Object.assign({ expiresIn }, ((options === null || options === void 0 ? void 0 : options.transform) ? { transform: options.transform } : {})), { headers: this.headers });
|
|
488
|
-
const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download)
|
|
489
|
-
? `&download=${options.download === true ? '' : options.download}`
|
|
490
|
-
: '';
|
|
491
|
-
const signedUrl = encodeURI(`${this.url}${data.signedURL}${downloadQueryParam}`);
|
|
492
|
-
data = { signedUrl };
|
|
493
|
-
return { data, error: null };
|
|
494
|
-
}
|
|
495
|
-
catch (error) {
|
|
496
|
-
if (this.shouldThrowOnError) {
|
|
497
|
-
throw error;
|
|
498
|
-
}
|
|
499
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
500
|
-
return { data: null, error };
|
|
501
|
-
}
|
|
502
|
-
throw error;
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* Creates multiple signed URLs. Use a signed URL to share a file for a fixed amount of time.
|
|
508
|
-
*
|
|
509
|
-
* @category File Buckets
|
|
510
|
-
* @param paths The file paths to be downloaded, including the current file names. For example `['folder/image.png', 'folder2/image2.png']`.
|
|
511
|
-
* @param expiresIn The number of seconds until the signed URLs expire. For example, `60` for URLs which are valid for one minute.
|
|
512
|
-
* @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
|
|
513
|
-
* @returns Promise with response containing array of objects with signedUrl, path, and error or error
|
|
514
|
-
*
|
|
515
|
-
* @example Create Signed URLs
|
|
516
|
-
* ```js
|
|
517
|
-
* const { data, error } = await supabase
|
|
518
|
-
* .storage
|
|
519
|
-
* .from('avatars')
|
|
520
|
-
* .createSignedUrls(['folder/avatar1.png', 'folder/avatar2.png'], 60)
|
|
521
|
-
* ```
|
|
522
|
-
*
|
|
523
|
-
* Response:
|
|
524
|
-
* ```json
|
|
525
|
-
* {
|
|
526
|
-
* "data": [
|
|
527
|
-
* {
|
|
528
|
-
* "error": null,
|
|
529
|
-
* "path": "folder/avatar1.png",
|
|
530
|
-
* "signedURL": "/object/sign/avatars/folder/avatar1.png?token=<TOKEN>",
|
|
531
|
-
* "signedUrl": "https://example.supabase.co/storage/v1/object/sign/avatars/folder/avatar1.png?token=<TOKEN>"
|
|
532
|
-
* },
|
|
533
|
-
* {
|
|
534
|
-
* "error": null,
|
|
535
|
-
* "path": "folder/avatar2.png",
|
|
536
|
-
* "signedURL": "/object/sign/avatars/folder/avatar2.png?token=<TOKEN>",
|
|
537
|
-
* "signedUrl": "https://example.supabase.co/storage/v1/object/sign/avatars/folder/avatar2.png?token=<TOKEN>"
|
|
538
|
-
* }
|
|
539
|
-
* ],
|
|
540
|
-
* "error": null
|
|
541
|
-
* }
|
|
542
|
-
* ```
|
|
543
|
-
*/
|
|
544
|
-
createSignedUrls(paths, expiresIn, options) {
|
|
545
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
546
|
-
try {
|
|
547
|
-
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/object/sign/${this.bucketId}`, { expiresIn, paths }, { headers: this.headers });
|
|
548
|
-
const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download)
|
|
549
|
-
? `&download=${options.download === true ? '' : options.download}`
|
|
550
|
-
: '';
|
|
551
|
-
return {
|
|
552
|
-
data: data.map((datum) => (Object.assign(Object.assign({}, datum), { signedUrl: datum.signedURL
|
|
553
|
-
? encodeURI(`${this.url}${datum.signedURL}${downloadQueryParam}`)
|
|
554
|
-
: null }))),
|
|
555
|
-
error: null,
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
catch (error) {
|
|
559
|
-
if (this.shouldThrowOnError) {
|
|
560
|
-
throw error;
|
|
561
|
-
}
|
|
562
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
563
|
-
return { data: null, error };
|
|
564
|
-
}
|
|
565
|
-
throw error;
|
|
566
|
-
}
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* Downloads a file from a private bucket. For public buckets, make a request to the URL returned from `getPublicUrl` instead.
|
|
571
|
-
*
|
|
572
|
-
* @category File Buckets
|
|
573
|
-
* @param path The full path and file name of the file to be downloaded. For example `folder/image.png`.
|
|
574
|
-
* @param options.transform Transform the asset before serving it to the client.
|
|
575
|
-
* @returns BlobDownloadBuilder instance for downloading the file
|
|
576
|
-
*
|
|
577
|
-
* @example Download file
|
|
578
|
-
* ```js
|
|
579
|
-
* const { data, error } = await supabase
|
|
580
|
-
* .storage
|
|
581
|
-
* .from('avatars')
|
|
582
|
-
* .download('folder/avatar1.png')
|
|
583
|
-
* ```
|
|
584
|
-
*
|
|
585
|
-
* Response:
|
|
586
|
-
* ```json
|
|
587
|
-
* {
|
|
588
|
-
* "data": <BLOB>,
|
|
589
|
-
* "error": null
|
|
590
|
-
* }
|
|
591
|
-
* ```
|
|
592
|
-
*
|
|
593
|
-
* @example Download file with transformations
|
|
594
|
-
* ```js
|
|
595
|
-
* const { data, error } = await supabase
|
|
596
|
-
* .storage
|
|
597
|
-
* .from('avatars')
|
|
598
|
-
* .download('folder/avatar1.png', {
|
|
599
|
-
* transform: {
|
|
600
|
-
* width: 100,
|
|
601
|
-
* height: 100,
|
|
602
|
-
* quality: 80
|
|
603
|
-
* }
|
|
604
|
-
* })
|
|
605
|
-
* ```
|
|
606
|
-
*/
|
|
607
|
-
download(path, options) {
|
|
608
|
-
const wantsTransformation = typeof (options === null || options === void 0 ? void 0 : options.transform) !== 'undefined';
|
|
609
|
-
const renderPath = wantsTransformation ? 'render/image/authenticated' : 'object';
|
|
610
|
-
const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {});
|
|
611
|
-
const queryString = transformationQuery ? `?${transformationQuery}` : '';
|
|
612
|
-
const _path = this._getFinalPath(path);
|
|
613
|
-
const downloadFn = () => (0, fetch_1.get)(this.fetch, `${this.url}/${renderPath}/${_path}${queryString}`, {
|
|
614
|
-
headers: this.headers,
|
|
615
|
-
noResolveJson: true,
|
|
616
|
-
});
|
|
617
|
-
return new BlobDownloadBuilder_1.default(downloadFn, this.shouldThrowOnError);
|
|
618
|
-
}
|
|
619
|
-
/**
|
|
620
|
-
* Retrieves the details of an existing file.
|
|
621
|
-
*
|
|
622
|
-
* @category File Buckets
|
|
623
|
-
* @param path The file path, including the file name. For example `folder/image.png`.
|
|
624
|
-
* @returns Promise with response containing file metadata or error
|
|
625
|
-
*
|
|
626
|
-
* @example Get file info
|
|
627
|
-
* ```js
|
|
628
|
-
* const { data, error } = await supabase
|
|
629
|
-
* .storage
|
|
630
|
-
* .from('avatars')
|
|
631
|
-
* .info('folder/avatar1.png')
|
|
632
|
-
* ```
|
|
633
|
-
*/
|
|
634
|
-
info(path) {
|
|
635
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
636
|
-
const _path = this._getFinalPath(path);
|
|
637
|
-
try {
|
|
638
|
-
const data = yield (0, fetch_1.get)(this.fetch, `${this.url}/object/info/${_path}`, {
|
|
639
|
-
headers: this.headers,
|
|
640
|
-
});
|
|
641
|
-
return { data: (0, helpers_1.recursiveToCamel)(data), error: null };
|
|
642
|
-
}
|
|
643
|
-
catch (error) {
|
|
644
|
-
if (this.shouldThrowOnError) {
|
|
645
|
-
throw error;
|
|
646
|
-
}
|
|
647
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
648
|
-
return { data: null, error };
|
|
649
|
-
}
|
|
650
|
-
throw error;
|
|
651
|
-
}
|
|
652
|
-
});
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* Checks the existence of a file.
|
|
656
|
-
*
|
|
657
|
-
* @category File Buckets
|
|
658
|
-
* @param path The file path, including the file name. For example `folder/image.png`.
|
|
659
|
-
* @returns Promise with response containing boolean indicating file existence or error
|
|
660
|
-
*
|
|
661
|
-
* @example Check file existence
|
|
662
|
-
* ```js
|
|
663
|
-
* const { data, error } = await supabase
|
|
664
|
-
* .storage
|
|
665
|
-
* .from('avatars')
|
|
666
|
-
* .exists('folder/avatar1.png')
|
|
667
|
-
* ```
|
|
668
|
-
*/
|
|
669
|
-
exists(path) {
|
|
670
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
671
|
-
const _path = this._getFinalPath(path);
|
|
672
|
-
try {
|
|
673
|
-
yield (0, fetch_1.head)(this.fetch, `${this.url}/object/${_path}`, {
|
|
674
|
-
headers: this.headers,
|
|
675
|
-
});
|
|
676
|
-
return { data: true, error: null };
|
|
677
|
-
}
|
|
678
|
-
catch (error) {
|
|
679
|
-
if (this.shouldThrowOnError) {
|
|
680
|
-
throw error;
|
|
681
|
-
}
|
|
682
|
-
if ((0, errors_1.isStorageError)(error) && error instanceof errors_1.StorageUnknownError) {
|
|
683
|
-
const originalError = error.originalError;
|
|
684
|
-
if ([400, 404].includes(originalError === null || originalError === void 0 ? void 0 : originalError.status)) {
|
|
685
|
-
return { data: false, error };
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
throw error;
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.
|
|
694
|
-
* This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.
|
|
695
|
-
*
|
|
696
|
-
* @category File Buckets
|
|
697
|
-
* @param path The path and name of the file to generate the public URL for. For example `folder/image.png`.
|
|
698
|
-
* @param options.download Triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
|
|
699
|
-
* @param options.transform Transform the asset before serving it to the client.
|
|
700
|
-
* @returns Object with public URL
|
|
701
|
-
*
|
|
702
|
-
* @example Returns the URL for an asset in a public bucket
|
|
703
|
-
* ```js
|
|
704
|
-
* const { data } = supabase
|
|
705
|
-
* .storage
|
|
706
|
-
* .from('public-bucket')
|
|
707
|
-
* .getPublicUrl('folder/avatar1.png')
|
|
708
|
-
* ```
|
|
709
|
-
*
|
|
710
|
-
* Response:
|
|
711
|
-
* ```json
|
|
712
|
-
* {
|
|
713
|
-
* "data": {
|
|
714
|
-
* "publicUrl": "https://example.supabase.co/storage/v1/object/public/public-bucket/folder/avatar1.png"
|
|
715
|
-
* }
|
|
716
|
-
* }
|
|
717
|
-
* ```
|
|
718
|
-
*
|
|
719
|
-
* @example Returns the URL for an asset in a public bucket with transformations
|
|
720
|
-
* ```js
|
|
721
|
-
* const { data } = supabase
|
|
722
|
-
* .storage
|
|
723
|
-
* .from('public-bucket')
|
|
724
|
-
* .getPublicUrl('folder/avatar1.png', {
|
|
725
|
-
* transform: {
|
|
726
|
-
* width: 100,
|
|
727
|
-
* height: 100,
|
|
728
|
-
* }
|
|
729
|
-
* })
|
|
730
|
-
* ```
|
|
731
|
-
*
|
|
732
|
-
* @example Returns the URL which triggers the download of an asset in a public bucket
|
|
733
|
-
* ```js
|
|
734
|
-
* const { data } = supabase
|
|
735
|
-
* .storage
|
|
736
|
-
* .from('public-bucket')
|
|
737
|
-
* .getPublicUrl('folder/avatar1.png', {
|
|
738
|
-
* download: true,
|
|
739
|
-
* })
|
|
740
|
-
* ```
|
|
741
|
-
*/
|
|
742
|
-
getPublicUrl(path, options) {
|
|
743
|
-
const _path = this._getFinalPath(path);
|
|
744
|
-
const _queryString = [];
|
|
745
|
-
const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download)
|
|
746
|
-
? `download=${options.download === true ? '' : options.download}`
|
|
747
|
-
: '';
|
|
748
|
-
if (downloadQueryParam !== '') {
|
|
749
|
-
_queryString.push(downloadQueryParam);
|
|
750
|
-
}
|
|
751
|
-
const wantsTransformation = typeof (options === null || options === void 0 ? void 0 : options.transform) !== 'undefined';
|
|
752
|
-
const renderPath = wantsTransformation ? 'render/image' : 'object';
|
|
753
|
-
const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {});
|
|
754
|
-
if (transformationQuery !== '') {
|
|
755
|
-
_queryString.push(transformationQuery);
|
|
756
|
-
}
|
|
757
|
-
let queryString = _queryString.join('&');
|
|
758
|
-
if (queryString !== '') {
|
|
759
|
-
queryString = `?${queryString}`;
|
|
760
|
-
}
|
|
761
|
-
return {
|
|
762
|
-
data: { publicUrl: encodeURI(`${this.url}/${renderPath}/public/${_path}${queryString}`) },
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
/**
|
|
766
|
-
* Deletes files within the same bucket
|
|
767
|
-
*
|
|
768
|
-
* @category File Buckets
|
|
769
|
-
* @param paths An array of files to delete, including the path and file name. For example [`'folder/image.png'`].
|
|
770
|
-
* @returns Promise with response containing array of deleted file objects or error
|
|
771
|
-
*
|
|
772
|
-
* @example Delete file
|
|
773
|
-
* ```js
|
|
774
|
-
* const { data, error } = await supabase
|
|
775
|
-
* .storage
|
|
776
|
-
* .from('avatars')
|
|
777
|
-
* .remove(['folder/avatar1.png'])
|
|
778
|
-
* ```
|
|
779
|
-
*
|
|
780
|
-
* Response:
|
|
781
|
-
* ```json
|
|
782
|
-
* {
|
|
783
|
-
* "data": [],
|
|
784
|
-
* "error": null
|
|
785
|
-
* }
|
|
786
|
-
* ```
|
|
787
|
-
*/
|
|
788
|
-
remove(paths) {
|
|
789
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
790
|
-
try {
|
|
791
|
-
const data = yield (0, fetch_1.remove)(this.fetch, `${this.url}/object/${this.bucketId}`, { prefixes: paths }, { headers: this.headers });
|
|
792
|
-
return { data, error: null };
|
|
793
|
-
}
|
|
794
|
-
catch (error) {
|
|
795
|
-
if (this.shouldThrowOnError) {
|
|
796
|
-
throw error;
|
|
797
|
-
}
|
|
798
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
799
|
-
return { data: null, error };
|
|
800
|
-
}
|
|
801
|
-
throw error;
|
|
802
|
-
}
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Get file metadata
|
|
807
|
-
* @param id the file id to retrieve metadata
|
|
808
|
-
*/
|
|
809
|
-
// async getMetadata(
|
|
810
|
-
// id: string
|
|
811
|
-
// ): Promise<
|
|
812
|
-
// | {
|
|
813
|
-
// data: Metadata
|
|
814
|
-
// error: null
|
|
815
|
-
// }
|
|
816
|
-
// | {
|
|
817
|
-
// data: null
|
|
818
|
-
// error: StorageError
|
|
819
|
-
// }
|
|
820
|
-
// > {
|
|
821
|
-
// try {
|
|
822
|
-
// const data = await get(this.fetch, `${this.url}/metadata/${id}`, { headers: this.headers })
|
|
823
|
-
// return { data, error: null }
|
|
824
|
-
// } catch (error) {
|
|
825
|
-
// if (isStorageError(error)) {
|
|
826
|
-
// return { data: null, error }
|
|
827
|
-
// }
|
|
828
|
-
// throw error
|
|
829
|
-
// }
|
|
830
|
-
// }
|
|
831
|
-
/**
|
|
832
|
-
* Update file metadata
|
|
833
|
-
* @param id the file id to update metadata
|
|
834
|
-
* @param meta the new file metadata
|
|
835
|
-
*/
|
|
836
|
-
// async updateMetadata(
|
|
837
|
-
// id: string,
|
|
838
|
-
// meta: Metadata
|
|
839
|
-
// ): Promise<
|
|
840
|
-
// | {
|
|
841
|
-
// data: Metadata
|
|
842
|
-
// error: null
|
|
843
|
-
// }
|
|
844
|
-
// | {
|
|
845
|
-
// data: null
|
|
846
|
-
// error: StorageError
|
|
847
|
-
// }
|
|
848
|
-
// > {
|
|
849
|
-
// try {
|
|
850
|
-
// const data = await post(
|
|
851
|
-
// this.fetch,
|
|
852
|
-
// `${this.url}/metadata/${id}`,
|
|
853
|
-
// { ...meta },
|
|
854
|
-
// { headers: this.headers }
|
|
855
|
-
// )
|
|
856
|
-
// return { data, error: null }
|
|
857
|
-
// } catch (error) {
|
|
858
|
-
// if (isStorageError(error)) {
|
|
859
|
-
// return { data: null, error }
|
|
860
|
-
// }
|
|
861
|
-
// throw error
|
|
862
|
-
// }
|
|
863
|
-
// }
|
|
864
|
-
/**
|
|
865
|
-
* Lists all the files and folders within a path of the bucket.
|
|
866
|
-
*
|
|
867
|
-
* @category File Buckets
|
|
868
|
-
* @param path The folder path.
|
|
869
|
-
* @param options Search options including limit (defaults to 100), offset, sortBy, and search
|
|
870
|
-
* @param parameters Optional fetch parameters including signal for cancellation
|
|
871
|
-
* @returns Promise with response containing array of files or error
|
|
872
|
-
*
|
|
873
|
-
* @example List files in a bucket
|
|
874
|
-
* ```js
|
|
875
|
-
* const { data, error } = await supabase
|
|
876
|
-
* .storage
|
|
877
|
-
* .from('avatars')
|
|
878
|
-
* .list('folder', {
|
|
879
|
-
* limit: 100,
|
|
880
|
-
* offset: 0,
|
|
881
|
-
* sortBy: { column: 'name', order: 'asc' },
|
|
882
|
-
* })
|
|
883
|
-
* ```
|
|
884
|
-
*
|
|
885
|
-
* Response:
|
|
886
|
-
* ```json
|
|
887
|
-
* {
|
|
888
|
-
* "data": [
|
|
889
|
-
* {
|
|
890
|
-
* "name": "avatar1.png",
|
|
891
|
-
* "id": "e668cf7f-821b-4a2f-9dce-7dfa5dd1cfd2",
|
|
892
|
-
* "updated_at": "2024-05-22T23:06:05.580Z",
|
|
893
|
-
* "created_at": "2024-05-22T23:04:34.443Z",
|
|
894
|
-
* "last_accessed_at": "2024-05-22T23:04:34.443Z",
|
|
895
|
-
* "metadata": {
|
|
896
|
-
* "eTag": "\"c5e8c553235d9af30ef4f6e280790b92\"",
|
|
897
|
-
* "size": 32175,
|
|
898
|
-
* "mimetype": "image/png",
|
|
899
|
-
* "cacheControl": "max-age=3600",
|
|
900
|
-
* "lastModified": "2024-05-22T23:06:05.574Z",
|
|
901
|
-
* "contentLength": 32175,
|
|
902
|
-
* "httpStatusCode": 200
|
|
903
|
-
* }
|
|
904
|
-
* }
|
|
905
|
-
* ],
|
|
906
|
-
* "error": null
|
|
907
|
-
* }
|
|
908
|
-
* ```
|
|
909
|
-
*
|
|
910
|
-
* @example Search files in a bucket
|
|
911
|
-
* ```js
|
|
912
|
-
* const { data, error } = await supabase
|
|
913
|
-
* .storage
|
|
914
|
-
* .from('avatars')
|
|
915
|
-
* .list('folder', {
|
|
916
|
-
* limit: 100,
|
|
917
|
-
* offset: 0,
|
|
918
|
-
* sortBy: { column: 'name', order: 'asc' },
|
|
919
|
-
* search: 'jon'
|
|
920
|
-
* })
|
|
921
|
-
* ```
|
|
922
|
-
*/
|
|
923
|
-
list(path, options, parameters) {
|
|
924
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
925
|
-
try {
|
|
926
|
-
const body = Object.assign(Object.assign(Object.assign({}, DEFAULT_SEARCH_OPTIONS), options), { prefix: path || '' });
|
|
927
|
-
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/object/list/${this.bucketId}`, body, { headers: this.headers }, parameters);
|
|
928
|
-
return { data, error: null };
|
|
929
|
-
}
|
|
930
|
-
catch (error) {
|
|
931
|
-
if (this.shouldThrowOnError) {
|
|
932
|
-
throw error;
|
|
933
|
-
}
|
|
934
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
935
|
-
return { data: null, error };
|
|
936
|
-
}
|
|
937
|
-
throw error;
|
|
938
|
-
}
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* @experimental this method signature might change in the future
|
|
943
|
-
*
|
|
944
|
-
* @category File Buckets
|
|
945
|
-
* @param options search options
|
|
946
|
-
* @param parameters
|
|
947
|
-
*/
|
|
948
|
-
listV2(options, parameters) {
|
|
949
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
950
|
-
try {
|
|
951
|
-
const body = Object.assign({}, options);
|
|
952
|
-
const data = yield (0, fetch_1.post)(this.fetch, `${this.url}/object/list-v2/${this.bucketId}`, body, { headers: this.headers }, parameters);
|
|
953
|
-
return { data, error: null };
|
|
954
|
-
}
|
|
955
|
-
catch (error) {
|
|
956
|
-
if (this.shouldThrowOnError) {
|
|
957
|
-
throw error;
|
|
958
|
-
}
|
|
959
|
-
if ((0, errors_1.isStorageError)(error)) {
|
|
960
|
-
return { data: null, error };
|
|
961
|
-
}
|
|
962
|
-
throw error;
|
|
963
|
-
}
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
encodeMetadata(metadata) {
|
|
967
|
-
return JSON.stringify(metadata);
|
|
968
|
-
}
|
|
969
|
-
toBase64(data) {
|
|
970
|
-
if (typeof Buffer !== 'undefined') {
|
|
971
|
-
return Buffer.from(data).toString('base64');
|
|
972
|
-
}
|
|
973
|
-
return btoa(data);
|
|
974
|
-
}
|
|
975
|
-
_getFinalPath(path) {
|
|
976
|
-
return `${this.bucketId}/${path.replace(/^\/+/, '')}`;
|
|
977
|
-
}
|
|
978
|
-
_removeEmptyFolders(path) {
|
|
979
|
-
return path.replace(/^\/|\/$/g, '').replace(/\/+/g, '/');
|
|
980
|
-
}
|
|
981
|
-
transformOptsToQueryString(transform) {
|
|
982
|
-
const params = [];
|
|
983
|
-
if (transform.width) {
|
|
984
|
-
params.push(`width=${transform.width}`);
|
|
985
|
-
}
|
|
986
|
-
if (transform.height) {
|
|
987
|
-
params.push(`height=${transform.height}`);
|
|
988
|
-
}
|
|
989
|
-
if (transform.resize) {
|
|
990
|
-
params.push(`resize=${transform.resize}`);
|
|
991
|
-
}
|
|
992
|
-
if (transform.format) {
|
|
993
|
-
params.push(`format=${transform.format}`);
|
|
994
|
-
}
|
|
995
|
-
if (transform.quality) {
|
|
996
|
-
params.push(`quality=${transform.quality}`);
|
|
997
|
-
}
|
|
998
|
-
return params.join('&');
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
exports.default = StorageFileApi;
|
|
1002
|
-
//# sourceMappingURL=StorageFileApi.js.map
|