-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.dart
75 lines (68 loc) · 2.25 KB
/
example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Created by Jaimin on 12/01/24.
*/
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:developer' as developer;
import 'package:amazon_cognito_upload/amazon_cognito_upload.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runZonedGuarded(() {
runApp(const MyApp());
}, (dynamic error, dynamic stack) {
developer.log("Something went wrong!", error: error, stackTrace: stack);
});
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late Uint8List imageByte;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: const Color(0x9f4376f8),
),
home: Scaffold(
appBar: AppBar(
title: Text('Amazon s3 bucket image upload'),
elevation: 4,
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Click button to upload image'),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
AWSWebClient.uploadFile(
s3UploadUrl: 'S3_UPLOAD_URL', //your bucket url
s3SecretKey: 'S3_SECRET_KEY', //your secret key
s3Region: 'S3_REGION', //your region
s3AccessKey:'S3_ACCESS_KEY' , //your access key
s3BucketName: 'S3_BUCKET', //your bucket name
folderName: 'profile', //This folder name will auto generate folder in your bucket
fileName: 'imagedata.png', //your file name
fileBytes: imageByte, //your file bytes Note: it will take file as byte so you have to convert file into byte
);
},
child: Text('Upload Image'),
),
],
),
),
);
}
}