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:

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

final minio = Minio(
	endPoint: 's3.filebase.com',
	accessKey: 'YOUR-ACCESSKEYID',
	secretKey: 'YOUR-SECRETACCESSKEY',
	useSSL: true,
);

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

import 'package:minio/io.dart';
import 'package:minio/minio.dart';
void main() async {
	final minio = Minio(
		endPoint: 's3.filebase.com',
		accessKey: 'YOUR-ACCESSKEYID',
		secretKey: 'YOUR-SECRETACCESSKEY',
		useSSL: true,
);

await minio.fPutObject('filebase-sample-bucket', 'myobject', '/path/to/object');

}

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.

import 'dart:io';
import 'package:minio/minio.dart';
void main() async {
	final minio = Minio(
		endPoint: 's3.filebase.com',
		accessKey: 'YOUR-ACCESSKEYID',
		secretKey: 'YOUR-SECRETACCESSKEY',
);

final stream = await minio.getObject('filebase-sample-bucket', 'myobject');

// Get object length
print(stream.contentLength);

// Write object data stream to file
await stream.pipe(File('output.txt').openWrite());

}

Full Example

The following code example showcases a complete code example using the minio-dart package. Replace values as necessary to match your configuration.

import 'package:minio/io.dart';
import 'package:minio/minio.dart';
void main() async {
	final minio = Minio(
		endPoint: 's3.filebase.com',
		accessKey: 'YOUR-ACCESSKEYID',
		secretKey: 'YOUR-SECRETACCESSKEY',
		useSSL: true,
);
	final bucket = 'filebase-sample-bucket';
	final object = 'image.png';
	final copy1 = 'image.copy1.png';
	final copy2 = 'image.copy2.png';

	if (!await minio.bucketExists(bucket)) {
		await minio.makeBucket(bucket);
		print('bucket $bucket created');

	} else {
		print('bucket $bucket already exists');
}
	final poller = minio.listenBucketNotification(bucket, events: [
	's3:ObjectCreated:*',
]);
	poller.stream.listen((event) {
	print('--- event: ${event['eventName']}');
});
	final region = await minio.getBucketRegion('filebase-sample-bucket');
	print('--- object region:');
	print(region);
	
	final etag = await minio.fPutObject(bucket, object, 'example/$object');
	print('--- etag:');
	print(etag);

	final url = await minio.presignedGetObject(bucket, object, expires: 1000);
	print('--- presigned url:');
	print(url);

	final copyResult1 = await minio.copyObject(bucket, copy1, '$bucket/$object');
	final copyResult2 = await minio.copyObject(bucket, copy2, '$bucket/$object');
	print('--- copy1 etag:');
	print(copyResult1.eTag);
	print('--- copy2 etag:');
	print(copyResult2.eTag);

await minio.fGetObject(bucket, object, 'example/$copy1');
print('--- copy1 downloaded');

await minio.listObjects(bucket).forEach((chunk) {
print('--- objects:');

chunk.objects.forEach((o) => print(o.key));
});

await minio.listObjectsV2(bucket).forEach((chunk) {
print('--- objects(v2):');

chunk.objects.forEach((o) => print(o.key));
});

final stat = await minio.statObject(bucket, object);
print('--- object stat:');
print(stat.etag);
print(stat.size);
print(stat.lastModified);
print(stat.metaData);

await minio.removeObject(bucket, object);
print('--- object removed');

await minio.removeObjects(bucket, [copy1, copy2]);
print('--- copy1, copy2 removed');

await minio.removeBucket(bucket);
print('--- bucket removed');

poller.stop();
}

Last updated