pasubot_storage_client 0.0.1 copy "pasubot_storage_client: ^0.0.1" to clipboard
pasubot_storage_client: ^0.0.1 copied to clipboard

Dart client library to interact with Pasubot Storage. Pasubot Storage provides an interface for managing Files stored in S3, using Postgres to manage permissions.

example/main.dart

// ignore_for_file: avoid_print

import 'dart:io';
import 'dart:typed_data';

import 'package:pasubot_storage_client/storage_client.dart';

Future<void> main() async {
  const pasubotUrl = '';
  const pasubotKey = '';
  final client = PasubotStorageClient(
    '$pasubotUrl/storage/v1',
    {
      'Authorization': 'Bearer $pasubotKey',
    },
  );

  // Upload binary file
  final List<int> listBytes = 'Hello world'.codeUnits;
  final Uint8List fileData = Uint8List.fromList(listBytes);
  final uploadBinaryResponse = await client.from('public').uploadBinary(
        'binaryExample.txt',
        fileData,
        fileOptions: const FileOptions(upsert: true),
      );
  print('upload binary response : $uploadBinaryResponse');

  // Upload file to bucket "public"
  final file = File('example.txt');
  file.writeAsStringSync('File content');
  final storageResponse =
      await client.from('public').upload('example.txt', file);
  print('upload response : $storageResponse');

  // Get download url
  final urlResponse =
      await client.from('public').createSignedUrl('example.txt', 60);
  print('download url : $urlResponse');

  // Download text file
  try {
    final fileResponse = await client.from('public').download('example.txt');
    print('downloaded file : ${String.fromCharCodes(fileResponse)}');
  } catch (error) {
    print('Error while downloading file : $error');
  }

  // Delete file
  final deleteResponse = await client.from('public').remove(['example.txt']);
  print('deleted file id : ${deleteResponse.first.id}');

  // Local file cleanup
  if (file.existsSync()) file.deleteSync();
}
0
likes
120
points
6
downloads

Publisher

unverified uploader

Weekly Downloads

Dart client library to interact with Pasubot Storage. Pasubot Storage provides an interface for managing Files stored in S3, using Postgres to manage permissions.

Documentation

API reference

License

MIT (license)

Dependencies

http, http_parser, meta, mime, retry

More

Packages that depend on pasubot_storage_client