Giter Site home page Giter Site logo

cjng96 / flutter_aws_s3_client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from diagnosia/flutter_aws_s3_client

0.0 1.0 0.0 113 KB

A simple, unofficial AWS S3 client

License: MIT License

Shell 2.63% Objective-C 3.57% Java 1.73% Dart 92.06%

flutter_aws_s3_client's Introduction

Pub Package

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, 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

  const region = "eu-central-1";
  const bucketId = "yourBucketId";
  final AwsS3Client s3client = AwsS3Client(
      region: region,
      host: "s3.$region.amazonaws.com",
      bucketId: bucketId,
      accessKey: "<your access key>",
      secretKey: "<your secret key>");

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):

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());
  }
}

flutter_aws_s3_client's People

Contributors

cjng96 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.