@@ -241,6 +241,7 @@ RxAmplify.Storage.getUrl(StoragePath.fromString("public/example"), options).subs
241
241
242
242
Option | Type | Description |
243
243
| -- | -- | ----------- |
244
+ | bucket | StorageBucket | A string representing the target bucket's assigned name in Amplify Backend or an object specifying the bucket name and region from the console.<br /><br />Read more at [ Configure additional storage buckets] ( /[platform]/build-a-backend/storage/set-up-storage/#configure-additional-storage-buckets ) |
244
245
| expires | Integer | Number of seconds before the URL expires |
245
246
| useAccelerateEndpoint | Boolean | Flag to configure use of acceleration mode |
246
247
@@ -366,7 +367,7 @@ try {
366
367
RxProgressAwareSingleOperation<StorageDownloadFileResult > download =
367
368
RxAmplify . Storage . downloadFile(
368
369
StoragePath . fromString(" public/example" ),
369
- new File (getApplicationContext(). getFilesDir() + " /download.txt"
370
+ new File (getApplicationContext(). getFilesDir() + " /download.txt" )
370
371
);
371
372
372
373
download
@@ -650,6 +651,152 @@ try {
650
651
651
652
<InlineFilter filters = { [" android" ]} >
652
653
654
+ ### Download from a specified bucket
655
+
656
+ You can also perform an download operation to a specific bucket by providing the ` bucket ` option. You can pass in a string representing the target bucket's assigned name in Amplify Backend.
657
+
658
+ <BlockSwitcher >
659
+ <Block name = " Java" >
660
+
661
+ ``` java
662
+ StorageBucket secondBucket = StorageBucket . fromOutputs(" secondBucket" );
663
+ StorageDownloadFileOptions options = StorageDownloadFileOptions . builder(). bucket(secondBucket). build();
664
+ Amplify . Storage . downloadFile(
665
+ StoragePath . fromString(" public/example" ),
666
+ new File (getApplicationContext(). getFilesDir() + " /download.txt" ),
667
+ options,
668
+ result - > Log . i(" MyAmplifyApp" , " Successfully downloaded: " + result. getFile(). getName()),
669
+ error - > Log . e(" MyAmplifyApp" , " Download Failure" , error)
670
+ );
671
+ ```
672
+
673
+ </Block >
674
+ <Block name = " Kotlin - Callbacks" >
675
+
676
+ ``` kotlin
677
+ val secondBucket = StorageBucket .fromOutputs(" secondBucket" )
678
+ val options = StorageDownloadFileOptions .builder().bucket(secondBucket).build()
679
+ val file = File (" ${applicationContext.filesDir} /download.txt" )
680
+ Amplify .Storage .downloadFile(StoragePath .fromString(" public/example" ), file, option,
681
+ { Log .i(" MyAmplifyApp" , " Successfully downloaded: ${it.file.name} " ) },
682
+ { Log .e(" MyAmplifyApp" , " Download Failure" , it) }
683
+ )
684
+ ```
685
+
686
+ </Block >
687
+ <Block name = " Kotlin - Coroutines" >
688
+
689
+ ``` kotlin
690
+ val secondBucket = StorageBucket .fromOutputs(" secondBucket" )
691
+ val options = StorageDownloadFileOptions .builder().bucket(secondBucket).build()
692
+ val file = File (" ${applicationContext.filesDir} /download.txt" )
693
+ val download = Amplify .Storage .downloadFile(StoragePath .fromString(" public/example" ), file, options)
694
+ try {
695
+ val fileName = download.result().file.name
696
+ Log .i(" MyAmplifyApp" , " Successfully downloaded: $fileName " )
697
+ } catch (error: StorageException ) {
698
+ Log .e(" MyAmplifyApp" , " Download Failure" , error)
699
+ }
700
+ ```
701
+
702
+ </Block >
703
+ <Block name = " RxJava" >
704
+
705
+ ``` java
706
+ StorageBucket secondBucket = StorageBucket . fromOutputs(" secondBucket" );
707
+ StorageDownloadFileOptions options = StorageDownloadFileOptions . builder(). bucket(secondBucket). build();
708
+ RxProgressAwareSingleOperation<StorageDownloadFileResult > download =
709
+ RxAmplify . Storage . downloadFile(
710
+ StoragePath . fromString(" public/example" ),
711
+ new File (getApplicationContext(). getFilesDir() + " /download.txt" ),
712
+ options
713
+ );
714
+
715
+ download
716
+ .observeResult()
717
+ .subscribe(
718
+ result - > Log . i(" MyAmplifyApp" , " Successfully downloaded: " + result. getFile(). getName()),
719
+ error - > Log . e(" MyAmplifyApp" , " Download Failure" , error)
720
+ );
721
+ ```
722
+
723
+ </Block >
724
+ </BlockSwitcher >
725
+
726
+ Alternatively, you can also pass in an object by specifying the bucket name and region from the console.
727
+
728
+ <BlockSwitcher >
729
+ <Block name = " Java" >
730
+
731
+ ``` java
732
+ BucketInfo bucketInfo = new BucketInfo (" second-bucket-name-from-console" , " us-east-2" );
733
+ StorageBucket secondBucket = StorageBucket . fromBucketInfo(bucketInfo);
734
+ StorageDownloadFileOptions options = StorageDownloadFileOptions . builder(). bucket(secondBucket). build();
735
+ Amplify . Storage . downloadFile(
736
+ StoragePath . fromString(" public/example" ),
737
+ new File (getApplicationContext(). getFilesDir() + " /download.txt" ),
738
+ options,
739
+ result - > Log . i(" MyAmplifyApp" , " Successfully downloaded: " + result. getFile(). getName()),
740
+ error - > Log . e(" MyAmplifyApp" , " Download Failure" , error)
741
+ );
742
+ ```
743
+
744
+ </Block >
745
+ <Block name = " Kotlin - Callbacks" >
746
+
747
+ ``` kotlin
748
+ val bucketInfo = BucketInfo (" second-bucket-name-from-console" , " us-east-2" )
749
+ val secondBucket = StorageBucket .fromBucketInfo(bucketInfo)
750
+ val options = StorageDownloadFileOptions .builder().bucket(secondBucket).build()
751
+ val file = File (" ${applicationContext.filesDir} /download.txt" )
752
+ Amplify .Storage .downloadFile(StoragePath .fromString(" public/example" ), file, options,
753
+ { Log .i(" MyAmplifyApp" , " Successfully downloaded: ${it.file.name} " ) },
754
+ { Log .e(" MyAmplifyApp" , " Download Failure" , it) }
755
+ )
756
+ ```
757
+
758
+ </Block >
759
+ <Block name = " Kotlin - Coroutines" >
760
+
761
+ ``` kotlin
762
+ val bucketInfo = BucketInfo (" second-bucket-name-from-console" , " us-east-2" )
763
+ val secondBucket = StorageBucket .fromBucketInfo(bucketInfo)
764
+ val options = StorageDownloadFileOptions .builder().bucket(secondBucket).build()
765
+ val file = File (" ${applicationContext.filesDir} /download.txt" )
766
+ val download = Amplify .Storage .downloadFile(StoragePath .fromString(" public/example" ), file, options)
767
+ try {
768
+ val fileName = download.result().file.name
769
+ Log .i(" MyAmplifyApp" , " Successfully downloaded: $fileName " )
770
+ } catch (error: StorageException ) {
771
+ Log .e(" MyAmplifyApp" , " Download Failure" , error)
772
+ }
773
+ ```
774
+
775
+ </Block >
776
+ <Block name = " RxJava" >
777
+
778
+ ``` java
779
+ BucketInfo bucketInfo = new BucketInfo (" second-bucket-name-from-console" , " us-east-2" );
780
+ StorageBucket secondBucket = StorageBucket . fromBucketInfo(bucketInfo);
781
+ StorageDownloadFileOptions options = StorageDownloadFileOptions . builder(). bucket(secondBucket). build();
782
+ RxProgressAwareSingleOperation<StorageDownloadFileResult > download =
783
+ RxAmplify . Storage . downloadFile(
784
+ StoragePath . fromString(" public/example" ),
785
+ new File (getApplicationContext(). getFilesDir() + " /download.txt" ),
786
+ options,
787
+ );
788
+
789
+ download
790
+ .observeResult()
791
+ .subscribe(
792
+ result - > Log . i(" MyAmplifyApp" , " Successfully downloaded: " + result. getFile(). getName()),
793
+ error - > Log . e(" MyAmplifyApp" , " Download Failure" , error)
794
+ );
795
+ ```
796
+
797
+ </Block >
798
+ </BlockSwitcher >
799
+
653
800
### Monitor download progress
654
801
655
802
<BlockSwitcher >
0 commit comments