createBucket method
Future<String>
createBucket(
- String id,
- [BucketOptions bucketOptions = const BucketOptions(public: false)]
inherited
Creates a new Storage bucket
id
is a unique identifier for the bucket you are creating.
bucketOptions
is a parameter to optionally make the bucket public.
It returns the newly created bucket it. To get the bucket reference, use getBucket:
void bucket() async {
final newBucketId = await createBucket('images');
final bucket = await Bucket(newBucketId);
print('${bucket.id}');
}
Implementation
Future<String> createBucket(
String id, [
BucketOptions bucketOptions = const BucketOptions(public: false),
]) async {
final FetchOptions options = FetchOptions(headers: headers);
final response = await storageFetch.post(
'$url/bucket',
{
'id': id,
'name': id,
'public': bucketOptions.public,
if (bucketOptions.fileSizeLimit != null)
'file_size_limit': bucketOptions.fileSizeLimit,
if (bucketOptions.allowedMimeTypes != null)
'allowed_mime_types': bucketOptions.allowedMimeTypes,
},
options: options,
);
final bucketId = (response as Map<String, dynamic>)['name'] as String;
return bucketId;
}