https://github.com/diagnosia/flutter_aws_s3_client
A simple, unofficial AWS S3 client
https://github.com/diagnosia/flutter_aws_s3_client
aws dart flutter s3
Last synced: 4 months ago
JSON representation
A simple, unofficial AWS S3 client
- Host: GitHub
- URL: https://github.com/diagnosia/flutter_aws_s3_client
- Owner: diagnosia
- License: mit
- Created: 2019-06-24T12:25:18.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-03-23T13:29:28.000Z (over 5 years ago)
- Last Synced: 2023-08-20T21:57:40.786Z (almost 3 years ago)
- Topics: aws, dart, flutter, s3
- Language: Dart
- Size: 94.7 KB
- Stars: 25
- Watchers: 3
- Forks: 19
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pub.dartlang.org/packages/flutter_aws_s3_client)
# DEPRECATED
Since there is now an official package for accessing AWS services, I decided to not longer support this package. please migrate to https://github.com/aws-amplify/amplify-flutter / https://pub.dev/packages/amplify_storage_s3/example
# flutter_aws_s3_client
Supports downloading objects and listing objects in a bucket.
The heavy lifting was done by [Amazon Cognito Identity SDK for Dart](https://github.com/furaiev/amazon-cognito-identity-dart-2),
this project contains just convenience methods for common use cases.
if you need more requests, you can use this instead to build what you need.
If you implement more methods, feel free to open a pull request.
## Usage
### Build the client
```dart
const region = "eu-central-1";
const bucketId = "yourBucketId";
final AwsS3Client s3client = AwsS3Client(
region: region,
host: "s3.$region.amazonaws.com",
bucketId: bucketId,
accessKey: "",
secretKey: "");
```
### Get an object
final response = await s3client.getObject("your/object/key");
### List objects of the bucket
ListBucketResult listBucketResult =
await s3client.listObjects(prefix: "dir1/dir2/", delimiter: "/");
print(listBucketResult.toString());
If you want to use a custom http client, use the method `buildSignedGetParams`.
This method returns an object containing the URL and the Authorization headers, which can be
used to build the request with your preferred http client.
### Download a large object to a file without keeping everything in-memory (streaming)
Use the `buildSignedGetParams` method.
Example code (with ETag support):
```dart
Future download(String key, File file, [String etag = null]) async {
final signedParams = awsS3Client.buildSignedGetParams(key: key);
final request = await HttpClient().getUrl(signedParams.uri);
for (final header in (signedParams.headers ?? const {}).entries) {
request.headers.add(header.key, header.value);
}
if(eTag != null){
request.headers.add(HttpHeaders.ifNoneMatchHeader, eTag);
}
final response = response = await request.close();
if(response.statusCode != HttpStatus.ok){
//handle error
}else{
return response.pipe(file.openWrite());
}
}
```