@@ -273,12 +273,12 @@ let url = try await Amplify.Storage.getURL(
273
273
)
274
274
```
275
275
276
- ### More ` getURL ` options
276
+ ### All ` getURL ` options
277
277
278
278
Option | Type | Description |
279
279
| -- | -- | ----------- |
280
- | expires | Integer | Number of seconds before the URL expires |
281
- | bucket | StorageBucket | The bucket in which the file is stored |
280
+ | expires | Int | Number of seconds before the URL expires |
281
+ | bucket | StorageBucket | The bucket in which the object is stored |
282
282
283
283
</InlineFilter >
284
284
@@ -304,9 +304,8 @@ Future<void> getDownloadUrl() async {
304
304
305
305
</InlineFilter >
306
306
307
- ## Download to a file
308
-
309
307
<InlineFilter filters = { [" react" , " angular" , " javascript" , " vue" , " nextjs" , " react-native" ]} >
308
+ ## Download to a file
310
309
311
310
Use the ` downloadData ` API to download the file locally.
312
311
@@ -321,6 +320,7 @@ const { body, eTag } = await downloadData({
321
320
</InlineFilter >
322
321
323
322
<InlineFilter filters = { [" android" ]} >
323
+ ## Download to a file
324
324
325
325
Use the ` downloadFile ` API to download the file locally on the client.
326
326
@@ -386,6 +386,8 @@ download
386
386
</InlineFilter >
387
387
388
388
<InlineFilter filters = { [" swift" ]} >
389
+ ## Download files
390
+ ### Download to a local file
389
391
390
392
Use the ` downloadFile ` API to download the file locally on the client.
391
393
@@ -446,6 +448,57 @@ let resultSink = downloadTask
446
448
</Block >
447
449
</BlockSwitcher >
448
450
451
+ ### Download to data in memory
452
+
453
+ You can download to in-memory buffer [ Data] ( https://developer.apple.com/documentation/foundation/data ) object with ` Amplify.Storage.downloadData ` :
454
+
455
+ <BlockSwitcher >
456
+
457
+ <Block name = " Async/Await" >
458
+
459
+ ``` swift
460
+ let downloadTask = Amplify.Storage .downloadData (
461
+ path : .fromString (" public/example/path" )
462
+ )
463
+ Task {
464
+ for await progress in await downloadTask.progress {
465
+ print (" Progress: \( progress ) " )
466
+ }
467
+ }
468
+ let data = try await downloadTask.value
469
+ print (" Completed: \( data ) " )
470
+ ```
471
+
472
+ </Block >
473
+
474
+ <Block name = " Combine" >
475
+
476
+ ``` swift
477
+ let downloadTask = Amplify.Storage .downloadData (
478
+ path : .fromString (" public/example/path" )
479
+ )
480
+ let progressSink = downloadTask
481
+ .inProcessPublisher
482
+ .sink { progress in
483
+ print (" Progress: \( progress ) " )
484
+ }
485
+
486
+ let resultSink = downloadTask
487
+ .resultPublisher
488
+ .sink {
489
+ if case let .failure (storageError) = $0 {
490
+ print (" Failed: \( storageError.errorDescription ) . \( storageError.recoverySuggestion ) " )
491
+ }
492
+ }
493
+ receiveValue : { data in
494
+ print (" Completed: \( data ) " )
495
+ }
496
+ ```
497
+
498
+ </Block >
499
+
500
+ </BlockSwitcher >
501
+
449
502
### Download from a specified bucket
450
503
451
504
You can also perform a download operation from a specific bucket by providing the ` bucket ` option
@@ -455,20 +508,30 @@ You can also perform a download operation from a specific bucket by providing th
455
508
You can use ` .fromOutputs(name:) ` to provide a string representing the target bucket's assigned name in the Amplify Backend.
456
509
457
510
``` swift
511
+ // Download to File
458
512
let downloadTask = Amplify.Storage .downloadFile (
459
513
path : .fromString (" public/example/path" ),
460
514
local : downloadToFileUrl,
461
515
options : .init (
462
516
bucket : .fromOutputs (name : " secondBucket" )
463
517
)
464
518
)
519
+
520
+ // Download to Data
521
+ let downloadTask = Amplify.Storage .downloadData (
522
+ path : .fromString (" public/example/path" ),
523
+ options : .init (
524
+ bucket : .fromOutputs (name : " secondBucket" )
525
+ )
526
+ )
465
527
```
466
528
</Block >
467
529
468
530
<Block name = " From Bucket Info" >
469
531
You can also use ` .fromBucketInfo(_:) ` to provide a bucket name and region directly.
470
532
471
533
``` swift
534
+ // Download to File
472
535
let downloadTask = Amplify.Storage .downloadFile (
473
536
path : .fromString (" public/example/path" ),
474
537
local : downloadToFileUrl,
@@ -479,13 +542,25 @@ let downloadTask = Amplify.Storage.downloadFile(
479
542
)
480
543
)
481
544
)
545
+
546
+ // Download to Data
547
+ let downloadTask = Amplify.Storage .downloadData (
548
+ path : .fromString (" public/example/path" ),
549
+ options : .init (
550
+ bucket : .fromBucketInfo (.init (
551
+ bucketName : " another-bucket-name" ,
552
+ region : " another-bucket-region" )
553
+ )
554
+ )
555
+ )
482
556
```
483
557
</Block >
484
558
</BlockSwitcher >
485
559
486
560
</InlineFilter >
487
561
488
562
<InlineFilter filters = { [" flutter" ]} >
563
+ ## Download to a file
489
564
490
565
You can download a file to a local directory using ` Amplify.Storage.downloadFile ` .
491
566
@@ -563,61 +638,6 @@ try {
563
638
```
564
639
</InlineFilter >
565
640
566
- <InlineFilter filters = { [" swift" ]} >
567
-
568
- ## Download to data in memory
569
-
570
- You can download to in-memory buffer [ Data] ( https://developer.apple.com/documentation/foundation/data ) object with ` Amplify.Storage.downloadData ` :
571
-
572
- <BlockSwitcher >
573
-
574
- <Block name = " Async/Await" >
575
-
576
- ``` swift
577
- let downloadTask = Amplify.Storage .downloadData (
578
- path : .fromString (" public/example/path" )
579
- )
580
- Task {
581
- for await progress in await downloadTask.progress {
582
- print (" Progress: \( progress ) " )
583
- }
584
- }
585
- let data = try await downloadTask.value
586
- print (" Completed: \( data ) " )
587
- ```
588
-
589
- </Block >
590
-
591
- <Block name = " Combine" >
592
-
593
- ``` swift
594
- let downloadTask = Amplify.Storage .downloadData (
595
- path : .fromString (" public/example/path" )
596
- )
597
- let progressSink = downloadTask
598
- .inProcessPublisher
599
- .sink { progress in
600
- print (" Progress: \( progress ) " )
601
- }
602
-
603
- let resultSink = downloadTask
604
- .resultPublisher
605
- .sink {
606
- if case let .failure (storageError) = $0 {
607
- print (" Failed: \( storageError.errorDescription ) . \( storageError.recoverySuggestion ) " )
608
- }
609
- }
610
- receiveValue : { data in
611
- print (" Completed: \( data ) " )
612
- }
613
- ```
614
-
615
- </Block >
616
-
617
- </BlockSwitcher >
618
-
619
- </InlineFilter >
620
-
621
641
<InlineFilter filters = { [" react" , " angular" , " javascript" , " vue" , " nextjs" , " react-native" ]} >
622
642
623
643
### Download from a specified bucket
@@ -1118,42 +1138,7 @@ final operation = Amplify.Storage.downloadData(
1118
1138
1119
1139
<InlineFilter filters = { [" swift" ]} >
1120
1140
1121
- ### Download from a specified bucket
1122
-
1123
- You can also perform a download operation from a specific bucket by providing the ` bucket ` option
1124
-
1125
- <BlockSwitcher >
1126
- <Block name = " From Outputs" >
1127
- You can use ` .fromOutputs(name:) ` to provide a string representing the target bucket's assigned name in the Amplify Backend.
1128
-
1129
- ``` swift
1130
- let downloadTask = Amplify.Storage .downloadData (
1131
- path : .fromString (" public/example/path" ),
1132
- options : .init (
1133
- bucket : .fromOutputs (name : " secondBucket" )
1134
- )
1135
- )
1136
- ```
1137
- </Block >
1138
-
1139
- <Block name = " From Bucket Info" >
1140
- You can also use ` .fromBucketInfo(_:) ` to provide a bucket name and region directly.
1141
-
1142
- ``` swift
1143
- let downloadTask = Amplify.Storage .downloadData (
1144
- path : .fromString (" public/example/path" ),
1145
- options : .init (
1146
- bucket : .fromBucketInfo (.init (
1147
- bucketName : " another-bucket-name" ,
1148
- region : " another-bucket-region" )
1149
- )
1150
- )
1151
- )
1152
- ```
1153
- </Block >
1154
- </BlockSwitcher >
1155
-
1156
- ## Pause, resume, and cancel downloads
1141
+ ### Pause, resume, and cancel downloads
1157
1142
1158
1143
Calls to ` downloadData ` or ` downloadFile ` return a reference to the task that is actually performing the download.
1159
1144
@@ -1171,6 +1156,12 @@ Download tasks are run using `URLSessionTask` instances internally. You can lear
1171
1156
1172
1157
</Callout >
1173
1158
1159
+ ### All ` download ` options
1160
+
1161
+ | Option | Type | Description |
1162
+ | --- | --- | --- |
1163
+ | bucket | StorageBucket | The bucket in which the object should be stored |
1164
+
1174
1165
</InlineFilter >
1175
1166
1176
1167
<InlineFilter filters = { [" react" , " angular" , " javascript" , " vue" , " nextjs" , " react-native" ]} >
0 commit comments