-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(multi-bucket): add multi-bucket support to storage components #5562
base: main
Are you sure you want to change the base?
Changes from 21 commits
82099b3
f45e688
130914d
6759502
6d200a9
77de102
5ea81d5
98b51db
79d1209
9916524
bb0c2f7
0fab899
77119df
cd12258
4c6eae2
d36d03e
f3953b6
fabf129
8cbbd05
757226b
f825df3
e96c3f3
a5c3d5e
68c0a84
21c0763
f6645f1
5787b6c
55a141a
2895e9b
cc79b45
23e7619
b2349b1
2674696
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@aws-amplify/ui-react-storage': minor | ||
--- | ||
|
||
Support for multiple buckets added to storage image and file uploader |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { FileUploader } from '@aws-amplify/ui-react-storage'; | ||
|
||
export const App = () => { | ||
return ( | ||
<FileUploader | ||
acceptedFileTypes={['image/*']} | ||
bucket={{ | ||
bucketName: 'my-bucket-xxxxxxxx', | ||
region: 'us-west-2', | ||
}} | ||
path="public/" | ||
maxFileCount={1} | ||
/> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { FileUploader } from '@aws-amplify/ui-react-storage'; | ||
|
||
export const App = () => { | ||
return ( | ||
<FileUploader | ||
acceptedFileTypes={['image/*']} | ||
bucket="my-bucket" | ||
path="public/" | ||
maxFileCount={1} | ||
/> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import amplifyOutputs from '@environments/storage/gen2/amplify_outputs'; | ||
export default amplifyOutputs; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as React from 'react'; | ||
|
||
import { Amplify } from 'aws-amplify'; | ||
import { Text, Loader } from '@aws-amplify/ui-react'; | ||
import { StorageImage } from '@aws-amplify/ui-react-storage'; | ||
import '@aws-amplify/ui-react/styles.css'; | ||
import amplifyOutputs from './amplify_outputs'; | ||
|
||
Amplify.configure(amplifyOutputs); | ||
|
||
export function StorageImageExample() { | ||
const [isFirstImgLoaded, setIsFirstImgLoaded] = React.useState(false); | ||
const [isSecondImgLoaded, setIsSecondImgLoaded] = React.useState(false); | ||
|
||
return ( | ||
<> | ||
<StorageImage | ||
alt="public cat 1" | ||
bucket="StorageEndToEnd" | ||
path="public/public-e2e.jpeg" | ||
onLoad={() => setIsFirstImgLoaded(true)} | ||
/> | ||
{isFirstImgLoaded ? ( | ||
<Text>The first public image is loaded.</Text> | ||
) : ( | ||
<Loader testId="Loader1" /> | ||
)} | ||
<StorageImage | ||
alt="public cat 2" | ||
bucket="StorageEndToEndSecondary" | ||
path={() => 'public/public-e2e.jpeg'} | ||
onLoad={() => setIsSecondImgLoaded(true)} | ||
/> | ||
{isSecondImgLoaded ? ( | ||
<Text>The second public image is loaded.</Text> | ||
) : ( | ||
<Loader testId="Loader2" /> | ||
)} | ||
</> | ||
); | ||
} | ||
export default StorageImageExample; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Feature: Load two images, each from a different S3 bucket with public access level settings | ||
|
||
Background: | ||
Given I'm running the example "ui/components/storage/storage-image/multi-bucket" | ||
|
||
@react | ||
Scenario: I successfully load two images from two buckets | ||
Then I see "Loader1" element | ||
Then I see "Loader2" element | ||
Then I see the "public cat 1" image | ||
Then I see the "public cat 2" image | ||
Then I see "The first public image is loaded." | ||
Then I see "The second public image is loaded." |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { isFunction } from '@aws-amplify/ui'; | |
|
||
import { PathCallback, uploadFile } from '../../utils'; | ||
import { getInput } from '../../utils'; | ||
import { StorageBucket } from '../../types'; | ||
import { FileStatus } from '../../types'; | ||
import { FileUploaderProps } from '../../types'; | ||
Comment on lines
+8
to
10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can be consolidated to a single import statement (same with the '../../utils' imports) |
||
import { UseFileUploader } from '../useFileUploader'; | ||
|
@@ -25,11 +26,13 @@ export interface UseUploadFilesProps | |
'setUploadingFile' | 'setUploadProgress' | 'setUploadSuccess' | 'files' | ||
> { | ||
accessLevel?: FileUploaderProps['accessLevel']; | ||
bucket?: StorageBucket; | ||
path?: string | PathCallback; | ||
} | ||
|
||
export function useUploadFiles({ | ||
accessLevel, | ||
bucket, | ||
files, | ||
isResumable, | ||
maxFileCount, | ||
|
@@ -68,6 +71,7 @@ export function useUploadFiles({ | |
if (file) { | ||
const input = getInput({ | ||
accessLevel, | ||
bucket, | ||
file, | ||
key, | ||
onProgress, | ||
|
@@ -105,6 +109,7 @@ export function useUploadFiles({ | |
}, [ | ||
files, | ||
accessLevel, | ||
bucket, | ||
isResumable, | ||
setUploadProgress, | ||
setUploadingFile, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,15 @@ import { | |
} from './ui'; | ||
import { FileUploaderDisplayText, PathCallback, UploadTask } from './utils'; | ||
|
||
export interface BucketInfo { | ||
bucketName: string; | ||
region: string; | ||
} | ||
|
||
// accepts either a 'friendly name' that the user has assigned | ||
// or an object containing the region as well as the name generated by the backend | ||
export type StorageBucket = string | BucketInfo; | ||
|
||
export enum FileStatus { | ||
ADDED = 'added', | ||
QUEUED = 'queued', | ||
|
@@ -68,6 +77,10 @@ export interface FileUploaderProps { | |
* Determines if the upload will automatically start after a file is selected, default value: true | ||
*/ | ||
autoUpload?: boolean; | ||
/** | ||
* Designates the bucket to upload to, if the user has multiple buckets configured | ||
*/ | ||
bucket?: StorageBucket; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as the one on StorageManager, not sure this is needed since multi bucket support doesn't exist in Gen1? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
/** | ||
* Component overrides | ||
*/ | ||
|
@@ -141,5 +154,6 @@ export interface FileUploaderPathProps | |
*/ | ||
path: string | PathCallback; | ||
accessLevel?: never; | ||
bucket?: StorageBucket; | ||
useAccelerateEndpoint?: boolean; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ describe('getInput', () => { | |
const expected: UploadDataWithPathInput = { | ||
data: file, | ||
options: { | ||
bucket: undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to add explicit |
||
contentType: file.type, | ||
useAccelerateEndpoint: undefined, | ||
onProgress, | ||
|
@@ -78,6 +79,7 @@ describe('getInput', () => { | |
const expected: UploadDataWithPathInput = { | ||
data: file, | ||
options: { | ||
bucket: undefined, | ||
contentType: file.type, | ||
useAccelerateEndpoint: undefined, | ||
onProgress, | ||
|
@@ -97,6 +99,7 @@ describe('getInput', () => { | |
data: file, | ||
options: { | ||
accessLevel, | ||
bucket: undefined, | ||
contentType: file.type, | ||
useAccelerateEndpoint: undefined, | ||
onProgress, | ||
|
@@ -116,6 +119,7 @@ describe('getInput', () => { | |
data: file, | ||
options: { | ||
accessLevel, | ||
bucket: undefined, | ||
contentType: file.type, | ||
useAccelerateEndpoint: undefined, | ||
onProgress, | ||
|
@@ -134,6 +138,7 @@ describe('getInput', () => { | |
const expected: UploadDataWithPathInput = { | ||
data: file, | ||
options: { | ||
bucket: undefined, | ||
contentType: file.type, | ||
useAccelerateEndpoint: undefined, | ||
onProgress, | ||
|
@@ -155,6 +160,7 @@ describe('getInput', () => { | |
const expected: UploadDataWithPathInput = { | ||
data: file, | ||
options: { | ||
bucket: undefined, | ||
contentDisposition, | ||
contentType: file.type, | ||
metadata, | ||
|
@@ -188,6 +194,7 @@ describe('getInput', () => { | |
const expected: UploadDataWithPathInput = { | ||
data, | ||
options: { | ||
bucket: undefined, | ||
contentType: 'binary/octet-stream', | ||
useAccelerateEndpoint: undefined, | ||
onProgress, | ||
|
@@ -207,6 +214,7 @@ describe('getInput', () => { | |
const expected: UploadDataWithPathInput = { | ||
data, | ||
options: { | ||
bucket: undefined, | ||
contentType: 'binary/octet-stream', | ||
useAccelerateEndpoint: true, | ||
onProgress, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public cat 1 is from the first bucket and public cat 2 is from the second bucket