Skip to content

Commit c229b65

Browse files
authored
feat(Storage): Implementing support for multiple buckets (#3839)
1 parent d55f04b commit c229b65

35 files changed

+3075
-120
lines changed

Amplify/Categories/Storage/Operation/Request/StorageDownloadDataRequest.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public extension StorageDownloadDataRequest {
6464
@available(*, deprecated, message: "Use `path` in Storage API instead of `Options`")
6565
public let targetIdentityId: String?
6666

67+
/// A Storage Bucket that contains the object to download. Defaults to `nil`, in which case the default one will be used.
68+
///
69+
/// - Tag: StorageDownloadDataRequest.bucket
70+
public let bucket: (any StorageBucket)?
71+
6772
/// Extra plugin specific options, only used in special circumstances when the existing options do not provide
6873
/// a way to utilize the underlying storage system's functionality. See plugin documentation for expected
6974
/// key/values
@@ -91,11 +96,14 @@ public extension StorageDownloadDataRequest {
9196
///
9297
/// - Tag: StorageDownloadDataRequestOptions.init
9398
@available(*, deprecated, message: "Use init(pluginOptions)")
94-
public init(accessLevel: StorageAccessLevel = .guest,
95-
targetIdentityId: String? = nil,
96-
pluginOptions: Any? = nil) {
99+
public init(
100+
accessLevel: StorageAccessLevel = .guest,
101+
targetIdentityId: String? = nil,
102+
pluginOptions: Any? = nil
103+
) {
97104
self.accessLevel = accessLevel
98105
self.targetIdentityId = targetIdentityId
106+
self.bucket = nil
99107
self.pluginOptions = pluginOptions
100108
}
101109

@@ -104,6 +112,18 @@ public extension StorageDownloadDataRequest {
104112
public init(pluginOptions: Any? = nil) {
105113
self.accessLevel = .guest
106114
self.targetIdentityId = nil
115+
self.bucket = nil
116+
self.pluginOptions = pluginOptions
117+
}
118+
119+
/// - Tag: StorageDownloadDataRequestOptions.init
120+
public init(
121+
bucket: some StorageBucket,
122+
pluginOptions: Any? = nil
123+
) {
124+
self.accessLevel = .guest
125+
self.targetIdentityId = nil
126+
self.bucket = bucket
107127
self.pluginOptions = pluginOptions
108128
}
109129
}

Amplify/Categories/Storage/Operation/Request/StorageDownloadFileRequest.swift

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public extension StorageDownloadFileRequest {
7171
@available(*, deprecated, message: "Use `path` in Storage API instead of `Options`")
7272
public let targetIdentityId: String?
7373

74+
/// A Storage Bucket that contains the object to download. Defaults to `nil`, in which case the default one will be used.
75+
///
76+
/// - Tag: StorageDownloadDataRequest.bucket
77+
public let bucket: (any StorageBucket)?
78+
7479
/// Extra plugin specific options, only used in special circumstances when the existing options do not provide
7580
/// a way to utilize the underlying storage system's functionality. See plugin documentation for expected
7681
/// key/values
@@ -80,19 +85,33 @@ public extension StorageDownloadFileRequest {
8085

8186
/// - Tag: StorageDownloadFileRequestOptions.init
8287
@available(*, deprecated, message: "Use init(pluginOptions)")
83-
public init(accessLevel: StorageAccessLevel = .guest,
84-
targetIdentityId: String? = nil,
85-
pluginOptions: Any? = nil) {
88+
public init(
89+
accessLevel: StorageAccessLevel = .guest,
90+
targetIdentityId: String? = nil,
91+
pluginOptions: Any? = nil
92+
) {
8693
self.accessLevel = accessLevel
8794
self.targetIdentityId = targetIdentityId
95+
self.bucket = nil
8896
self.pluginOptions = pluginOptions
8997
}
9098

9199
/// - Tag: StorageDownloadFileRequestOptions.init
92-
@available(*, deprecated, message: "Use init(pluginOptions)")
93100
public init(pluginOptions: Any? = nil) {
94101
self.accessLevel = .guest
95102
self.targetIdentityId = nil
103+
self.bucket = nil
104+
self.pluginOptions = pluginOptions
105+
}
106+
107+
/// - Tag: StorageDownloadFileRequestOptions.init
108+
public init(
109+
bucket: some StorageBucket,
110+
pluginOptions: Any? = nil
111+
) {
112+
self.accessLevel = .guest
113+
self.targetIdentityId = nil
114+
self.bucket = bucket
96115
self.pluginOptions = pluginOptions
97116
}
98117
}

Amplify/Categories/Storage/Operation/Request/StorageGetURLRequest.swift

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public extension StorageGetURLRequest {
7373
/// - Tag: StorageGetURLRequest.Options.expires
7474
public let expires: Int
7575

76+
/// A Storage Bucket that contains the object. Defaults to `nil`, in which case the default one will be used.
77+
///
78+
/// - Tag: StorageDownloadDataRequest.bucket
79+
public let bucket: (any StorageBucket)?
80+
7681
/// Extra plugin specific options, only used in special circumstances when the existing options do
7782
/// not provide a way to utilize the underlying storage system's functionality. See plugin
7883
/// documentation or
@@ -84,20 +89,39 @@ public extension StorageGetURLRequest {
8489

8590
/// - Tag: StorageGetURLRequest.Options.init
8691
@available(*, deprecated, message: "Use init(expires:pluginOptions)")
87-
public init(accessLevel: StorageAccessLevel = .guest,
88-
targetIdentityId: String? = nil,
89-
expires: Int = Options.defaultExpireInSeconds,
90-
pluginOptions: Any? = nil) {
92+
public init(
93+
accessLevel: StorageAccessLevel = .guest,
94+
targetIdentityId: String? = nil,
95+
expires: Int = Options.defaultExpireInSeconds,
96+
pluginOptions: Any? = nil
97+
) {
9198
self.accessLevel = accessLevel
9299
self.targetIdentityId = targetIdentityId
93100
self.expires = expires
101+
self.bucket = nil
94102
self.pluginOptions = pluginOptions
95103
}
96104

97105
/// - Tag: StorageGetURLRequest.Options.init
98-
public init(expires: Int = Options.defaultExpireInSeconds,
99-
pluginOptions: Any? = nil) {
106+
public init(
107+
expires: Int = Options.defaultExpireInSeconds,
108+
pluginOptions: Any? = nil
109+
) {
110+
self.expires = expires
111+
self.bucket = nil
112+
self.pluginOptions = pluginOptions
113+
self.accessLevel = .guest
114+
self.targetIdentityId = nil
115+
}
116+
117+
/// - Tag: StorageGetURLRequest.Options.init
118+
public init(
119+
expires: Int = Options.defaultExpireInSeconds,
120+
bucket: some StorageBucket,
121+
pluginOptions: Any? = nil
122+
) {
100123
self.expires = expires
124+
self.bucket = bucket
101125
self.pluginOptions = pluginOptions
102126
self.accessLevel = .guest
103127
self.targetIdentityId = nil

Amplify/Categories/Storage/Operation/Request/StorageListRequest.swift

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public extension StorageListRequest {
7878
/// - Tag: StorageListRequestOptions.pageSize
7979
public let pageSize: UInt
8080

81+
/// A Storage Bucket that contains the objects to list. Defaults to `nil`, in which case the default one will be used.
82+
///
83+
/// - Tag: StorageDownloadDataRequest.bucket
84+
public let bucket: (any StorageBucket)?
85+
8186
/// Opaque string indicating the page offset at which to resume a listing. This is usually a copy of
8287
/// the value from [StorageListResult.nextToken](x-source-tag://StorageListResult.nextToken).
8388
///
@@ -96,18 +101,39 @@ public extension StorageListRequest {
96101
public let pluginOptions: Any?
97102

98103
/// - Tag: StorageListRequestOptions.init
99-
public init(accessLevel: StorageAccessLevel = .guest,
100-
targetIdentityId: String? = nil,
101-
path: String? = nil,
102-
subpathStrategy: SubpathStrategy = .include,
103-
pageSize: UInt = 1000,
104-
nextToken: String? = nil,
105-
pluginOptions: Any? = nil) {
104+
public init(
105+
accessLevel: StorageAccessLevel = .guest,
106+
targetIdentityId: String? = nil,
107+
path: String? = nil,
108+
subpathStrategy: SubpathStrategy = .include,
109+
pageSize: UInt = 1000,
110+
nextToken: String? = nil,
111+
pluginOptions: Any? = nil
112+
) {
106113
self.accessLevel = accessLevel
107114
self.targetIdentityId = targetIdentityId
108115
self.path = path
109116
self.subpathStrategy = subpathStrategy
110117
self.pageSize = pageSize
118+
self.bucket = nil
119+
self.nextToken = nextToken
120+
self.pluginOptions = pluginOptions
121+
}
122+
123+
/// - Tag: StorageListRequestOptions.init
124+
public init(
125+
subpathStrategy: SubpathStrategy = .include,
126+
pageSize: UInt = 1000,
127+
bucket: some StorageBucket,
128+
nextToken: String? = nil,
129+
pluginOptions: Any? = nil
130+
) {
131+
self.accessLevel = .guest
132+
self.targetIdentityId = nil
133+
self.path = nil
134+
self.subpathStrategy = subpathStrategy
135+
self.pageSize = pageSize
136+
self.bucket = bucket
111137
self.nextToken = nextToken
112138
self.pluginOptions = pluginOptions
113139
}

Amplify/Categories/Storage/Operation/Request/StorageRemoveRequest.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public extension StorageRemoveRequest {
5656
@available(*, deprecated, message: "Use `path` in Storage API instead of `Options`")
5757
public let accessLevel: StorageAccessLevel
5858

59+
/// A Storage Bucket that contains the object to remove. Defaults to `nil`, in which case the default one will be used.
60+
///
61+
/// - Tag: StorageDownloadDataRequest.bucket
62+
public let bucket: (any StorageBucket)?
63+
5964
/// Extra plugin specific options, only used in special circumstances when the existing options do not provide
6065
/// a way to utilize the underlying storage system's functionality. See plugin documentation for expected
6166
/// key/values
@@ -64,9 +69,22 @@ public extension StorageRemoveRequest {
6469
public let pluginOptions: Any?
6570

6671
/// - Tag: StorageRemoveRequestOptions.init
67-
public init(accessLevel: StorageAccessLevel = .guest,
68-
pluginOptions: Any? = nil) {
72+
public init(
73+
accessLevel: StorageAccessLevel = .guest,
74+
pluginOptions: Any? = nil
75+
) {
6976
self.accessLevel = accessLevel
77+
self.bucket = nil
78+
self.pluginOptions = pluginOptions
79+
}
80+
81+
/// - Tag: StorageRemoveRequestOptions.init
82+
public init(
83+
bucket: some StorageBucket,
84+
pluginOptions: Any? = nil
85+
) {
86+
self.accessLevel = .guest
87+
self.bucket = bucket
7088
self.pluginOptions = pluginOptions
7189
}
7290
}

Amplify/Categories/Storage/Operation/Request/StorageUploadDataRequest.swift

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public extension StorageUploadDataRequest {
7575
/// - Tag: StorageUploadDataRequestOptions.metadata
7676
public let metadata: [String: String]?
7777

78+
/// A specific Storage Bucket to upload the data. Defaults to `nil`, in which case the default one will be used.
79+
///
80+
/// - Tag: StorageDownloadDataRequest.bucket
81+
public let bucket: (any StorageBucket)?
82+
7883
/// The standard MIME type describing the format of the object to store
7984
///
8085
/// - Tag: StorageUploadDataRequestOptions.contentType
@@ -89,27 +94,46 @@ public extension StorageUploadDataRequest {
8994

9095
/// - Tag: StorageUploadDataRequestOptions.init
9196
@available(*, deprecated, message: "Use init(metadata:contentType:options)")
92-
public init(accessLevel: StorageAccessLevel = .guest,
93-
targetIdentityId: String? = nil,
94-
metadata: [String: String]? = nil,
95-
contentType: String? = nil,
96-
pluginOptions: Any? = nil
97+
public init(
98+
accessLevel: StorageAccessLevel = .guest,
99+
targetIdentityId: String? = nil,
100+
metadata: [String: String]? = nil,
101+
contentType: String? = nil,
102+
pluginOptions: Any? = nil
97103
) {
98104
self.accessLevel = accessLevel
99105
self.targetIdentityId = targetIdentityId
100106
self.metadata = metadata
107+
self.bucket = nil
108+
self.contentType = contentType
109+
self.pluginOptions = pluginOptions
110+
}
111+
112+
/// - Tag: StorageUploadDataRequestOptions.init
113+
public init(
114+
metadata: [String: String]? = nil,
115+
contentType: String? = nil,
116+
pluginOptions: Any? = nil
117+
) {
118+
self.accessLevel = .guest
119+
self.targetIdentityId = nil
120+
self.metadata = metadata
121+
self.bucket = nil
101122
self.contentType = contentType
102123
self.pluginOptions = pluginOptions
103124
}
104125

105126
/// - Tag: StorageUploadDataRequestOptions.init
106-
public init(metadata: [String: String]? = nil,
107-
contentType: String? = nil,
108-
pluginOptions: Any? = nil
127+
public init(
128+
metadata: [String: String]? = nil,
129+
bucket: some StorageBucket,
130+
contentType: String? = nil,
131+
pluginOptions: Any? = nil
109132
) {
110133
self.accessLevel = .guest
111134
self.targetIdentityId = nil
112135
self.metadata = metadata
136+
self.bucket = bucket
113137
self.contentType = contentType
114138
self.pluginOptions = pluginOptions
115139
}

Amplify/Categories/Storage/Operation/Request/StorageUploadFileRequest.swift

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public extension StorageUploadFileRequest {
7272
/// - Tag: StorageUploadFileRequestOptions.metadata
7373
public let metadata: [String: String]?
7474

75+
/// A specific Storage Bucket to upload the file. Defaults to `nil`, in which case the default one will be used.
76+
///
77+
/// - Tag: StorageUploadFileRequestOptions.bucket
78+
public let bucket: (any StorageBucket)?
79+
7580
/// The standard MIME type describing the format of the object to store
7681
///
7782
/// - Tag: StorageUploadFileRequestOptions.contentType
@@ -86,27 +91,46 @@ public extension StorageUploadFileRequest {
8691

8792
/// - Tag: StorageUploadFileRequestOptions.init
8893
@available(*, deprecated, message: "Use init(metadata:contentType:pluginOptions)")
89-
public init(accessLevel: StorageAccessLevel = .guest,
90-
targetIdentityId: String? = nil,
91-
metadata: [String: String]? = nil,
92-
contentType: String? = nil,
93-
pluginOptions: Any? = nil
94+
public init(
95+
accessLevel: StorageAccessLevel = .guest,
96+
targetIdentityId: String? = nil,
97+
metadata: [String: String]? = nil,
98+
contentType: String? = nil,
99+
pluginOptions: Any? = nil
94100
) {
95101
self.accessLevel = accessLevel
96102
self.targetIdentityId = targetIdentityId
97103
self.metadata = metadata
104+
self.bucket = nil
105+
self.contentType = contentType
106+
self.pluginOptions = pluginOptions
107+
}
108+
109+
/// - Tag: StorageUploadFileRequestOptions.init
110+
public init(
111+
metadata: [String: String]? = nil,
112+
contentType: String? = nil,
113+
pluginOptions: Any? = nil
114+
) {
115+
self.accessLevel = .guest
116+
self.targetIdentityId = nil
117+
self.metadata = metadata
118+
self.bucket = nil
98119
self.contentType = contentType
99120
self.pluginOptions = pluginOptions
100121
}
101122

102123
/// - Tag: StorageUploadFileRequestOptions.init
103-
public init(metadata: [String: String]? = nil,
104-
contentType: String? = nil,
105-
pluginOptions: Any? = nil
124+
public init(
125+
metadata: [String: String]? = nil,
126+
bucket: some StorageBucket,
127+
contentType: String? = nil,
128+
pluginOptions: Any? = nil
106129
) {
107130
self.accessLevel = .guest
108131
self.targetIdentityId = nil
109132
self.metadata = metadata
133+
self.bucket = bucket
110134
self.contentType = contentType
111135
self.pluginOptions = pluginOptions
112136
}

0 commit comments

Comments
 (0)