File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ /* eslint-disable jsx-a11y/label-has-associated-control */
2+ import { uploadData } from 'aws-amplify/storage' ;
3+ import { randomUUID } from 'node:crypto' ;
4+
5+ async function uploadFile ( formData : FormData ) {
6+ 'use server' ;
7+
8+ try {
9+ const file = formData . get ( 'file' ) as File ;
10+
11+ const result = await uploadData ( {
12+ path : `incoming/${ randomUUID ( ) } ` ,
13+ data : file ,
14+ } ) . result ;
15+ console . log ( 'Succeeded:' , result ) ;
16+ } catch ( error ) {
17+ console . log ( 'Error :' , error ) ;
18+ }
19+ }
20+
21+ const UploadFilePage = async ( ) => {
22+ return (
23+ < form action = { uploadFile } >
24+ < label >
25+ < span > Upload a file</ span >
26+ < input type = 'file' name = 'file' />
27+ </ label >
28+ < button type = 'submit' > Submit</ button >
29+ </ form >
30+ ) ;
31+ } ;
32+
33+ export default UploadFilePage ;
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ const publicPaths = [
3535 / ^ \/ a u t h \/ s i g n i n $ / ,
3636 / ^ \/ a u t h \/ s i g n o u t $ / ,
3737 / ^ \/ a u t h \/ i d l e $ / ,
38+ / ^ \/ t e s t - f i l e - u p l o a d $ / ,
3839] ;
3940
4041function getContentSecurityPolicy ( nonce : string ) {
Original file line number Diff line number Diff line change @@ -53,6 +53,10 @@ export const BackendConfigHelper = {
5353 api_base_url : config . apiBaseUrl ,
5454 templates_table_name : config . templatesTableName ,
5555 } ,
56+ storage : {
57+ aws_region : 'eu-west-2' ,
58+ bucket_name : 'pdf-upload-test-bucket-2' ,
59+ } ,
5660 } ,
5761 null ,
5862 2
You can’t perform that action at this time.
0 commit comments