Dart / Flutter
Learn how to configure a Dart or Flutter app for use with Filebase.

What is Dart?

Dart is a programming language developed by Google that is designed for client and app development, such as desktop or mobile applications.

What is Flutter?

Flutter is an open-source user interface development kit created for use with Dart. Flutter is used to develop mobile applications for Android and iOS, and desktop applications for Linux, Mac, Windows and Google.
Read below to learn how to configure a Dart or Flutter app to be used with Filebase.

Prerequisites:

  • Import the minio-dart package into your app.
  • Have Your Filebase Access and Secret Keys. Learn how to view your access keys here.
  • Create a Filebase Bucket. Learn how to create a bucket here.
Filebase is unable to provide specific configurations or debugging for custom applications due to their individualized nature.

Initialize the MinIO Client

The following code example showcases how to initialize the MinIO Client using the minio-dart package. Replace the following values in the code to match your configuration:
  • accessKey: Your Filebase Access Key
  • secretKey: Your Filebase Secret Key
1
final minio = Minio(
2
endPoint: 's3.filebase.com',
3
accessKey: 'YOUR-ACCESSKEYID',
4
secretKey: 'YOUR-SECRETACCESSKEY',
5
useSSL: true,
6
);
Copied!

Object Upload

The following code example showcases how to upload an object using the minio-dart package. Replace the following values in the code to match your configuration:
  • accessKey: Your Filebase Access Key
  • secretKey: Your Filebase Secret Key
  • filebase-sample-bucket: Your Filebase Bucket Name
  • myobject: The Object Name to be Uploaded
  • /path/to/object: The local path to the object
1
import 'package:minio/io.dart';
2
import 'package:minio/minio.dart';
3
void main() async {
4
final minio = Minio(
5
endPoint: 's3.filebase.com',
6
accessKey: 'YOUR-ACCESSKEYID',
7
secretKey: 'YOUR-SECRETACCESSKEY',
8
useSSL: true,
9
);
10
11
await minio.fPutObject('filebase-sample-bucket', 'myobject', '/path/to/object');
12
13
}
Copied!

Get Object

The following code example showcases how to download an object using the minio-dart package. Replace the following values in the code to match your configuration:
  • accessKey: Your Filebase Access Key
  • secretKey: Your Filebase Secret Key
  • filebase-sample-bucket: Your Filebase Bucket Name
  • myobject: The Object Name to be downloaded.
1
import 'dart:io';
2
import 'package:minio/minio.dart';
3
void main() async {
4
final minio = Minio(
5
endPoint: 's3.filebase.com',
6
accessKey: 'YOUR-ACCESSKEYID',
7
secretKey: 'YOUR-SECRETACCESSKEY',
8
);
9
10
final stream = await minio.getObject('filebase-sample-bucket', 'myobject');
11
12
// Get object length
13
print(stream.contentLength);
14
15
// Write object data stream to file
16
await stream.pipe(File('output.txt').openWrite());
17
18
}
Copied!

Full Example

The following code example showcases a complete code example using the minio-dart package. Replace values as necessary to match your configuration.
1
import 'package:minio/io.dart';
2
import 'package:minio/minio.dart';
3
void main() async {
4
final minio = Minio(
5
endPoint: 's3.filebase.com',
6
accessKey: 'YOUR-ACCESSKEYID',
7
secretKey: 'YOUR-SECRETACCESSKEY',
8
useSSL: true,
9
);
10
final bucket = 'filebase-sample-bucket';
11
final object = 'image.png';
12
final copy1 = 'image.copy1.png';
13
final copy2 = 'image.copy2.png';
14
15
if (!await minio.bucketExists(bucket)) {
16
await minio.makeBucket(bucket);
17
print('bucket $bucket created');
18
19
} else {
20
print('bucket $bucket already exists');
21
}
22
final poller = minio.listenBucketNotification(bucket, events: [
23
's3:ObjectCreated:*',
24
]);
25
poller.stream.listen((event) {
26
print('--- event: ${event['eventName']}');
27
});
28
final region = await minio.getBucketRegion('filebase-sample-bucket');
29
print('--- object region:');
30
print(region);
31
32
final etag = await minio.fPutObject(bucket, object, 'example/$object');
33
print('--- etag:');
34
print(etag);
35
36
final url = await minio.presignedGetObject(bucket, object, expires: 1000);
37
print('--- presigned url:');
38
print(url);
39
40
final copyResult1 = await minio.copyObject(bucket, copy1, '$bucket/$object');
41
final copyResult2 = await minio.copyObject(bucket, copy2, '$bucket/$object');
42
print('--- copy1 etag:');
43
print(copyResult1.eTag);
44
print('--- copy2 etag:');
45
print(copyResult2.eTag);
46
47
await minio.fGetObject(bucket, object, 'example/$copy1');
48
print('--- copy1 downloaded');
49
50
await minio.listObjects(bucket).forEach((chunk) {
51
print('--- objects:');
52
53
chunk.objects.forEach((o) => print(o.key));
54
});
55
56
await minio.listObjectsV2(bucket).forEach((chunk) {
57
print('--- objects(v2):');
58
59
chunk.objects.forEach((o) => print(o.key));
60
});
61
62
final stat = await minio.statObject(bucket, object);
63
print('--- object stat:');
64
print(stat.etag);
65
print(stat.size);
66
print(stat.lastModified);
67
print(stat.metaData);
68
69
await minio.removeObject(bucket, object);
70
print('--- object removed');
71
72
await minio.removeObjects(bucket, [copy1, copy2]);
73
print('--- copy1, copy2 removed');
74
75
await minio.removeBucket(bucket);
76
print('--- bucket removed');
77
78
poller.stop();
79
}
Copied!
If you have any questions, please join our Discord server, or send us an email at [email protected]
Last modified 1mo ago