createBucket method

Future<StorageResponse<String>> createBucket(
  1. String id, [
  2. BucketOptions bucketOptions = const BucketOptions(public: false)
])
inherited

Creates a new Storage bucket

id A unique identifier for the bucket you are creating. bucketOptions A parameter to optionally make the bucket public.

Implementation

Future<StorageResponse<String>> createBucket(
  String id, [
  BucketOptions bucketOptions = const BucketOptions(public: false),
]) async {
  try {
    final FetchOptions options = FetchOptions(headers: headers);
    final response = await fetch.post(
      '$url/bucket',
      {'id': id, 'name': id, 'public': bucketOptions.public},
      options: options,
    );
    if (response.hasError) {
      return StorageResponse(error: response.error);
    } else {
      final bucketId = response.data['name'] as String;
      return StorageResponse<String>(data: bucketId);
    }
  } catch (e) {
    return StorageResponse(error: StorageError(e.toString()));
  }
}