From 8b93fe58e388af4d489392efb3b7c365ffd7e091 Mon Sep 17 00:00:00 2001 From: Harsh <6162866+harsh62@users.noreply.github.com> Date: Thu, 16 Apr 2026 12:38:56 -0400 Subject: [PATCH 1/2] docs(storage): add Swift examples for presigned upload URL --- .../frontend/storage/download-files/index.mdx | 25 ++++++++-- .../frontend/storage/upload-files/index.mdx | 50 +++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/pages/[platform]/frontend/storage/download-files/index.mdx b/src/pages/[platform]/frontend/storage/download-files/index.mdx index 67071d0226e..bf5421dbbba 100644 --- a/src/pages/[platform]/frontend/storage/download-files/index.mdx +++ b/src/pages/[platform]/frontend/storage/download-files/index.mdx @@ -284,12 +284,29 @@ let url = try await Amplify.Storage.getURL( ) ``` +### Generate a presigned upload URL + +You can also use `getURL` with `method: .put` to generate a presigned URL for uploading files. Learn more at [Upload using a presigned URL](/[platform]/frontend/storage/upload-files/#upload-using-a-presigned-url). + +```swift +let uploadUrl = try await Amplify.Storage.getURL( + path: .fromString("public/example/path"), + options: .init( + pluginOptions: AWSStorageGetURLOptions( + method: .put + ) + ) +) +``` + ### All `getURL` options -Option | Type | Description | -| -- | -- | ----------- | -| expires | Int | Number of seconds before the URL expires | -| bucket | StorageBucket | The bucket in which the object is stored | +Option | Type | Default | Description | +| -- | -- | :--: | ----------- | +| expires | Int | 18000 | Number of seconds before the URL expires | +| bucket | StorageBucket | Default bucket from Amplify configuration | The bucket in which the object is stored | +| pluginOptions.method | StorageAccessMethod | .get | `.get` generates a download URL. `.put` generates an upload URL. | +| pluginOptions.validateObjectExistence | Bool | false | Whether to check the object exists before generating the URL. Skipped when method is `.put`. | diff --git a/src/pages/[platform]/frontend/storage/upload-files/index.mdx b/src/pages/[platform]/frontend/storage/upload-files/index.mdx index 9a843437495..149b47abaad 100644 --- a/src/pages/[platform]/frontend/storage/upload-files/index.mdx +++ b/src/pages/[platform]/frontend/storage/upload-files/index.mdx @@ -1572,6 +1572,56 @@ func getTempUrls(securityScopedUrls: [URL]) -> [URL] { } ``` +## Upload using a presigned URL + +You can use the `getURL` API with `method: .put` to generate a presigned URL for uploading files directly to S3. This is useful when: + +- You need to integrate with third-party tools or libraries that only accept standard HTTP URL endpoints +- You want to share a temporary upload link with another client or service +- You need to upload from a context where the Amplify SDK is not available + +```swift +import Amplify +import AWSS3StoragePlugin + +// Generate a presigned URL for uploading +let uploadUrl = try await Amplify.Storage.getURL( + path: .fromString("public/uploads/photo.jpg"), + options: .init( + pluginOptions: AWSStorageGetURLOptions( + method: .put + ) + ) +) +``` + +Then use the presigned URL to upload the file with a standard HTTP `PUT` request: + +```swift +var request = URLRequest(url: uploadUrl) +request.httpMethod = "PUT" +request.httpBody = imageData + +let (_, response) = try await URLSession.shared.data(for: request) +let httpResponse = response as? HTTPURLResponse +print("Upload status: \(httpResponse?.statusCode ?? 0)") +``` + + + +When `method: .put` is specified, the `validateObjectExistence` option is ignored since the object may not exist yet. + + + +### Presigned URL upload options + +Option | Type | Default | Description | +| -- | -- | :--: | ----------- | +| pluginOptions.method | StorageAccessMethod | .get | `.get` generates a download URL. `.put` generates an upload URL. | +| expires | Int | 18000 | Number of seconds before the URL expires. | +| bucket | StorageBucket | Default bucket from Amplify configuration | The bucket in which the object is stored. | +| pluginOptions.validateObjectExistence | Bool | false | Whether to check the object exists before generating the URL. Skipped when method is `.put`. | + From a0203d1fd4adeec68cdf2df3d42e91d190ecfd19 Mon Sep 17 00:00:00 2001 From: Harsh <6162866+harsh62@users.noreply.github.com> Date: Thu, 16 Apr 2026 12:45:35 -0400 Subject: [PATCH 2/2] fix: move upload example from download page to callout link only --- .../frontend/storage/download-files/index.mdx | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/pages/[platform]/frontend/storage/download-files/index.mdx b/src/pages/[platform]/frontend/storage/download-files/index.mdx index bf5421dbbba..139e36bcb0d 100644 --- a/src/pages/[platform]/frontend/storage/download-files/index.mdx +++ b/src/pages/[platform]/frontend/storage/download-files/index.mdx @@ -284,21 +284,6 @@ let url = try await Amplify.Storage.getURL( ) ``` -### Generate a presigned upload URL - -You can also use `getURL` with `method: .put` to generate a presigned URL for uploading files. Learn more at [Upload using a presigned URL](/[platform]/frontend/storage/upload-files/#upload-using-a-presigned-url). - -```swift -let uploadUrl = try await Amplify.Storage.getURL( - path: .fromString("public/example/path"), - options: .init( - pluginOptions: AWSStorageGetURLOptions( - method: .put - ) - ) -) -``` - ### All `getURL` options Option | Type | Default | Description | @@ -308,6 +293,12 @@ Option | Type | Default | Description | | pluginOptions.method | StorageAccessMethod | .get | `.get` generates a download URL. `.put` generates an upload URL. | | pluginOptions.validateObjectExistence | Bool | false | Whether to check the object exists before generating the URL. Skipped when method is `.put`. | + + +You can also use `getURL` with `method: .put` to generate presigned URLs for uploading files directly to S3. Learn more at [Upload using a presigned URL](/[platform]/frontend/storage/upload-files/#upload-using-a-presigned-url). + + +