Skip to content

Commit 97e19e8

Browse files
authored
docs(storage): improve docs for storage methods (#605)
1 parent 8ad9dd5 commit 97e19e8

File tree

5 files changed

+59
-49
lines changed

5 files changed

+59
-49
lines changed

Sources/Storage/BucketOptions.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import Foundation
22

33
public struct BucketOptions: Sendable {
4+
/// The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. Bu default, buckets are private.
45
public let `public`: Bool
6+
/// Specifies the allowed mime types that this bucket can accept during upload. The default value is null, which allows files with all mime types to be uploaded. Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
57
public let fileSizeLimit: String?
8+
/// Specifies the max file size in bytes that can be uploaded to this bucket. The global file size limit takes precedence over this value. The default value is null, which doesn't set a per bucket file size limit.
69
public let allowedMimeTypes: [String]?
710

8-
public init(public: Bool = false, fileSizeLimit: String? = nil, allowedMimeTypes: [String]? = nil) {
11+
public init(
12+
public: Bool = false,
13+
fileSizeLimit: String? = nil,
14+
allowedMimeTypes: [String]? = nil
15+
) {
916
self.public = `public`
1017
self.fileSizeLimit = fileSizeLimit
1118
self.allowedMimeTypes = allowedMimeTypes

Sources/Storage/StorageBucketApi.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Helpers
77

88
/// Storage Bucket API
99
public class StorageBucketApi: StorageApi, @unchecked Sendable {
10-
/// Retrieves the details of all Storage buckets within an existing product.
10+
/// Retrieves the details of all Storage buckets within an existing project.
1111
public func listBuckets() async throws -> [Bucket] {
1212
try await execute(
1313
HTTPRequest(
@@ -42,6 +42,7 @@ public class StorageBucketApi: StorageApi, @unchecked Sendable {
4242
/// Creates a new Storage bucket.
4343
/// - Parameters:
4444
/// - id: A unique identifier for the bucket you are creating.
45+
/// - options: Options for creating the bucket.
4546
public func createBucket(_ id: String, options: BucketOptions = .init()) async throws {
4647
try await execute(
4748
HTTPRequest(
@@ -60,9 +61,10 @@ public class StorageBucketApi: StorageApi, @unchecked Sendable {
6061
)
6162
}
6263

63-
/// Updates a Storage bucket
64+
/// Updates a Storage bucket.
6465
/// - Parameters:
6566
/// - id: A unique identifier for the bucket you are updating.
67+
/// - options: Options for updating the bucket.
6668
public func updateBucket(_ id: String, options: BucketOptions) async throws {
6769
try await execute(
6870
HTTPRequest(

Sources/Storage/StorageFileApi.swift

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
124124

125125
/// Uploads a file to an existing bucket.
126126
/// - Parameters:
127-
/// - path: The relative file path. Should be of the format `folder/subfolder/filename.png`. The
128-
/// bucket must already exist before attempting to upload.
127+
/// - path: The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
129128
/// - data: The Data to be stored in the bucket.
130-
/// - options: HTTP headers. For example `cacheControl`
129+
/// - options: The options for the uploaded file.
131130
@discardableResult
132131
public func upload(
133132
_ path: String,
@@ -142,6 +141,11 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
142141
)
143142
}
144143

144+
/// Uploads a file to an existing bucket.
145+
/// - Parameters:
146+
/// - path: The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
147+
/// - fileURL: The file URL to be stored in the bucket.
148+
/// - options: The options for the uploaded file.
145149
@discardableResult
146150
public func upload(
147151
_ path: String,
@@ -158,10 +162,9 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
158162

159163
/// Replaces an existing file at the specified path with a new one.
160164
/// - Parameters:
161-
/// - path: The relative file path. Should be of the format `folder/subfolder`. The bucket
162-
/// already exist before attempting to upload.
165+
/// - path: The relative file path. Should be of the format `folder/subfolder`. The bucket already exist before attempting to upload.
163166
/// - data: The Data to be stored in the bucket.
164-
/// - options: HTTP headers. For example `cacheControl`
167+
/// - options: The options for the updated file.
165168
@discardableResult
166169
public func update(
167170
_ path: String,
@@ -178,10 +181,9 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
178181

179182
/// Replaces an existing file at the specified path with a new one.
180183
/// - Parameters:
181-
/// - path: The relative file path. Should be of the format `folder/subfolder`. The bucket
182-
/// already exist before attempting to upload.
184+
/// - path: The relative file path. Should be of the format `folder/subfolder`. The bucket already exist before attempting to upload.
183185
/// - fileURL: The file URL to be stored in the bucket.
184-
/// - options: HTTP headers. For example `cacheControl`
186+
/// - options: The options for the updated file.
185187
@discardableResult
186188
public func update(
187189
_ path: String,
@@ -196,10 +198,10 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
196198
)
197199
}
198200

199-
/// Moves an existing file, optionally renaming it at the same time.
201+
/// Moves an existing file to a new path.
200202
/// - Parameters:
201203
/// - source: The original file path, including the current file name. For example `folder/image.png`.
202-
/// - destination: The new file path, including the new file name. For example `folder/image-copy.png`.
204+
/// - destination: The new file path, including the new file name. For example `folder/image-new.png`.
203205
/// - options: The destination options.
204206
public func move(
205207
from source: String,
@@ -222,7 +224,7 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
222224
)
223225
}
224226

225-
/// Copies an existing file to a new path in the same bucket.
227+
/// Copies an existing file to a new path.
226228
/// - Parameters:
227229
/// - source: The original file path, including the current file name. For example `folder/image.png`.
228230
/// - destination: The new file path, including the new file name. For example `folder/image-copy.png`.
@@ -255,13 +257,10 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
255257
.Key
256258
}
257259

258-
/// Create signed url to download file without requiring permissions. This URL can be valid for a
259-
/// set number of seconds.
260+
/// Creates a signed URL. Use a signed URL to share a file for a fixed amount of time.
260261
/// - Parameters:
261-
/// - path: The file path to be downloaded, including the current file name. For example
262-
/// `folder/image.png`.
263-
/// - expiresIn: The number of seconds until the signed URL expires. For example, `60` for a URL
264-
/// which is valid for one minute.
262+
/// - path: The file path, including the current file name. For example `folder/image.png`.
263+
/// - expiresIn: The number of seconds until the signed URL expires. For example, `60` for a URL which is valid for one minute.
265264
/// - download: Trigger a download with the specified file name.
266265
/// - transform: Transform the asset before serving it to the client.
267266
public func createSignedURL(
@@ -291,13 +290,10 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
291290
return try makeSignedURL(response.signedURL, download: download)
292291
}
293292

294-
/// Create signed url to download file without requiring permissions. This URL can be valid for a
295-
/// set number of seconds.
293+
/// Creates a signed URL. Use a signed URL to share a file for a fixed amount of time.
296294
/// - Parameters:
297-
/// - path: The file path to be downloaded, including the current file name. For example
298-
/// `folder/image.png`.
299-
/// - expiresIn: The number of seconds until the signed URL expires. For example, `60` for a URL
300-
/// which is valid for one minute.
295+
/// - path: The file path, including the current file name. For example `folder/image.png`.
296+
/// - expiresIn: The number of seconds until the signed URL expires. For example, `60` for a URL which is valid for one minute.
301297
/// - download: Trigger a download with the default file name.
302298
/// - transform: Transform the asset before serving it to the client.
303299
public func createSignedURL(
@@ -316,10 +312,8 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
316312

317313
/// Creates multiple signed URLs. Use a signed URL to share a file for a fixed amount of time.
318314
/// - Parameters:
319-
/// - paths: The file paths to be downloaded, including the current file names. For example
320-
/// `["folder/image.png", "folder2/image2.png"]`.
321-
/// - expiresIn: The number of seconds until the signed URLs expire. For example, `60` for URLs
322-
/// which are valid for one minute.
315+
/// - paths: The file paths to be downloaded, including the current file names. For example `["folder/image.png", "folder2/image2.png"]`.
316+
/// - expiresIn: The number of seconds until the signed URLs expire. For example, `60` for URLs which are valid for one minute.
323317
/// - download: Trigger a download with the specified file name.
324318
public func createSignedURLs(
325319
paths: [String],
@@ -349,10 +343,8 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
349343

350344
/// Creates multiple signed URLs. Use a signed URL to share a file for a fixed amount of time.
351345
/// - Parameters:
352-
/// - paths: The file paths to be downloaded, including the current file names. For example
353-
/// `["folder/image.png", "folder2/image2.png"]`.
354-
/// - expiresIn: The number of seconds until the signed URLs expire. For example, `60` for URLs
355-
/// which are valid for one minute.
346+
/// - paths: The file paths to be downloaded, including the current file names. For example `["folder/image.png", "folder2/image2.png"]`.
347+
/// - expiresIn: The number of seconds until the signed URLs expire. For example, `60` for URLs which are valid for one minute.
356348
/// - download: Trigger a download with the default file name.
357349
public func createSignedURLs(
358350
paths: [String],
@@ -389,8 +381,8 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
389381

390382
/// Deletes files within the same bucket
391383
/// - Parameters:
392-
/// - paths: An array of files to be deletes, including the path and file name. For example
393-
/// [`folder/image.png`].
384+
/// - paths: An array of files to be deletes, including the path and file name. For example [`folder/image.png`].
385+
/// - Returns: A list of removed ``FileObject``.
394386
public func remove(paths: [String]) async throws -> [FileObject] {
395387
try await execute(
396388
HTTPRequest(
@@ -490,11 +482,13 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
490482
}
491483
}
492484

493-
/// Returns a public url for an asset.
485+
/// 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. 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.
494486
/// - Parameters:
495-
/// - path: The file path to the asset. For example `folder/image.png`.
487+
/// - path: The path and name of the file to generate the public URL for. For example `folder/image.png`.
496488
/// - download: Trigger a download with the specified file name.
497489
/// - options: Transform the asset before retrieving it on the client.
490+
///
491+
/// - Note: The bucket needs to be set to public, either via ``StorageBucketApi/updateBucket(_:options:)`` or by going to Storage on [supabase.com/dashboard](https://supabase.com/dashboard), clicking the overflow menu on a bucket and choosing "Make public".
498492
public func getPublicURL(
499493
path: String,
500494
download: String? = nil,
@@ -527,11 +521,13 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
527521
return generatedUrl
528522
}
529523

530-
/// Returns a public url for an asset.
524+
/// 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. 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.
531525
/// - Parameters:
532-
/// - path: The file path to the asset. For example `folder/image.png`.
526+
/// - path: The path and name of the file to generate the public URL for. For example `folder/image.png`.
533527
/// - download: Trigger a download with the default file name.
534528
/// - options: Transform the asset before retrieving it on the client.
529+
///
530+
/// - Note: The bucket needs to be set to public, either via ``StorageBucketApi/updateBucket(_:options:)`` or by going to Storage on [supabase.com/dashboard](https://supabase.com/dashboard), clicking the overflow menu on a bucket and choosing "Make public".
535531
public func getPublicURL(
536532
path: String,
537533
download: Bool,
@@ -540,14 +536,10 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
540536
try getPublicURL(path: path, download: download ? "" : nil, options: options)
541537
}
542538

543-
/// Creates a signed upload URL.
544-
/// - Parameter path: The file path, including the current file name. For example
545-
/// `folder/image.png`.
539+
/// Creates a signed upload URL. Signed upload URLs can be used to upload files to the bucket without further authentication. They are valid for 2 hours.
540+
/// - Parameter path: The file path, including the current file name. For example `folder/image.png`.
546541
/// - Returns: A URL that can be used to upload files to the bucket without further
547542
/// authentication.
548-
///
549-
/// - Note: Signed upload URLs can be used to upload files to the bucket without further
550-
/// authentication. They are valid for 2 hours.
551543
public func createSignedUploadURL(
552544
path: String,
553545
options: CreateSignedUploadURLOptions? = nil

Sources/Storage/TransformOptions.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import Foundation
22

3+
/// Transform the asset before serving it to the client.
34
public struct TransformOptions: Encodable, Sendable {
5+
/// The width of the image in pixels.
46
public var width: Int?
7+
/// The height of the image in pixels.
58
public var height: Int?
9+
/// The resize mode can be cover, contain or fill. Defaults to cover.
10+
/// Cover resizes the image to maintain it's aspect ratio while filling the entire width and height.
11+
/// Contain resizes the image to maintain it's aspect ratio while fitting the entire image within the width and height.
12+
/// Fill resizes the image to fill the entire width and height. If the object's aspect ratio does not match the width and height, the image will be stretched to fit.
613
public var resize: String?
14+
/// Set the quality of the returned image. A number from 20 to 100, with 100 being the highest quality. Defaults to 80.
715
public var quality: Int?
16+
/// Specify the format of the image requested.
817
public var format: String?
918

1019
public init(

Sources/Storage/Types.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public struct FileOptions: Sendable {
4848
/// The `Content-Type` header value.
4949
public var contentType: String?
5050

51-
/// When upsert is set to true, the file is overwritten if it exists. When set to false, an error
52-
/// is thrown if the object already exists. Defaults to false.
51+
/// When upsert is set to `true`, the file is overwritten if it exists. When set to `false`, an error
52+
/// is thrown if the object already exists. Defaults to `false`.
5353
public var upsert: Bool
5454

5555
/// The duplex option is a string parameter that enables or disables duplex streaming, allowing

0 commit comments

Comments
 (0)