nhost_storage_dart 2.0.5 nhost_storage_dart: ^2.0.5 copied to clipboard
Nhost Dart Storage Service SDK
Nhost Storage Dart SDK #
Nhost Storage API for Dart
Getting Started #
Get your subdomain and region from nhost dashboard User Authentication is needed in order to upload.
import 'package:nhost_auth_dart/nhost_auth_dart.dart';
import 'package:nhost_storage_dart/nhost_storage_dart.dart';
void main() async {
// Setup
final auth = NhostAuthClient(url: authUrl);
final storage = NhostStorageClient(
url: storageUrl,
// this must be passed form Auth session otherwise,
// the sessions are not shared and therefore, headers for API calls
// will be missed.
session: auth.userSession,
);
await auth.signInEmailPassword(
email: 'user-1@nhost.io',
password: 'password-1',
);
// Create a new file...
final fileMetadata = await storage.uploadString(
fileName: 'some_text_file.txt',
fileContents: 'abcdef abcdef abcdef abcdef abcdef',
mimeType: 'text/plain',
);
print('File uploaded!');
// ...turn around and download its contents...
final downloadedFileContent = await storage.downloadFile(fileMetadata.id);
print('Downloaded file contents:');
print(downloadedFileContent.body);
// ...then delete it.
await storage.delete(fileMetadata.id);
// Release
auth.close();
storage.close();
}
Latest Release #
dependencies:
nhost_auth_dart: ^2.0.0
nhost_storage_dart: ^2.0.0