simple_s3 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

simple_s3 #

An advance yet simple to use AWS S3 plugin for upload and deletion.

Simple S3 uses AWS Native SDKs for iOS and Android

Getting started #

Add dependency in pubspec.yaml

simple_s3: 0.2.1

Follow @ab_hi_j on Twitter

Features #

FeatureDescription
Supports all filesSimpleS3 auto detects content type of file by looking into extension
Set Access TypeAllows you to set access type of file ex. PublicRead, Private etc
Default is Public Read
TimestampTurned off by default if turned on allows you to append timestamp in file name.
Location of timestamp can be changed to either prefix or suffix
Default is prefix
Custom File NameAllows to change name of file about to upload.
Note : File name must contain extension.
Custom S3 folder pathAllows to upload file to specific folder in S3
Sub Region SupportAllows upload/delete operations on S3 having sub regions
Delete ObjectAllows deletion of file object
Auto Generates URLURL pointing to S3 file is auto generated.

Usage Examples #

Simple File Upload #


// returns url pointing to S3 file

String result = await SimpleS3.uploadFile(
				file, <--------------- Selected File
				bucketName, <--------- Your Bucket Name
				poolID, <------------- Your POOL ID
				AWSRegions.apSouth1 <- S3 server region
				);

Delete #


// returns bool

bool result = await SimpleS3.delete(
				filePath, <---------------- S3 File Path
				bucketName, <-------------- Your Bucket Name
				poolID, <------------------ Your POOL ID
				AWSRegions.apSouth1, <----- S3 server region
				);

// delete also supports sub-regions

Custom File Name #


// returns url pointing to S3 file

String result = await SimpleS3.uploadFile(
				file, <------------------------------ Selected File
				bucketName, <------------------------ Your Bucket Name
				poolID, <---------------------------- Your POOL ID
				AWSRegions.apSouth1, <--------------- S3 server region
				fileName: "Dennis_ritchie.jpeg", <--- Custom file name
				);

Custom S3 Path #


// returns url pointing to S3 file

String result = await SimpleS3.uploadFile(
				file, <-------------------------------- Selected File
				bucketName, <--------------------------- Your Bucket Name
				poolID, <------------------------------- Your POOL ID
				AWSRegions.apSouth1, <------------------ S3 server region
				s3FolderPath: "users/profile_pics", <--- Custom S3 path
				);

// final path will be  "bucketName/users/profile_pics"

Setting Access Control #


// returns url pointing to S3 file

String result = await SimpleS3.uploadFile(
				file, <------------------------------------- Selected File
				bucketName, <------------------------------- Your Bucket Name
				poolID, <----------------------------------- Your POOL ID
				AWSRegions.apSouth1, <---------------------- S3 server region
				accessControl: S3AccessControl.private, <--- Setting access of uploaded file **private**
				);

// S3AccessControl have more types of AccessControl ex. .publicRead, .publicReadWrite etc...

Using Timestamp #


// returns url pointing to S3 file

String result = await SimpleS3.uploadFile(
				file, <------------------------------------- Selected File
				bucketName, <------------------------------- Your Bucket Name
				poolID, <----------------------------------- Your POOL ID
				AWSRegions.apSouth1, <---------------------- S3 server region
				useTimeStamp: true, <----------------------- Enable Timestamp
				);

// default location of timestamp is prefix
// if original file name = "Dennis_ritchie.jpeg"
// then the result will be = "1591705658_Dennis_ritchie.jpeg"


// Change Timestamp Location



String result = await SimpleS3.uploadFile(
				file, <--------------------------------------- Selected File
				bucketName, <--------------------------------- Your Bucket Name
				poolID, <------------------------------------- Your POOL ID
				AWSRegions.apSouth1, <------------------------ S3 server region
				useTimeStamp: true, <------------------------- Enable Timestamp
				timeStampLocation: TimestampLocation.suffix,<- Changes timestamp location to suffix
				);
// if original file name = "Dennis_ritchie.jpeg"
// then the result will be = "Dennis_ritchie_1591705658.jpeg"

Using Sub-Region #


// returns url pointing to S3 file

String result = await SimpleS3.uploadFile(
				file, <------------------------------------- Selected File
				bucketName, <------------------------------- Your Bucket Name
				poolID, <----------------------------------- Your POOL ID
				AWSRegions.apSouth1, <---------------------- S3 server region
				subRegion: AWSRegions.apNorthEast1 <-------- Sub region
				);

Debug mode #


// for security reasons plugin uses less logs, to enable full logs -

String result = await SimpleS3.uploadFile(
				file, <--------------- Selected File
				bucketName, <--------- Your Bucket Name
				poolID, <------------- Your POOL ID
				AWSRegions.apSouth1 <- S3 server region
				debugLog: true, <----- Enable full logs
				);

0.0.1 #

Initial release

0.1.0 #

Refactor example update

0.2.0 #

Removed unused methods

0.2.1 #

Removed unused methods

example/lib/main.dart

import 'dart:async';
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: "S3 Upload/Delete Demo",
      home: Scaffold(body: SimpleS3Test()),
    );
  }
}

class SimpleS3Test extends StatefulWidget {
  @override
  SimpleS3TestState createState() => SimpleS3TestState();
}

class SimpleS3TestState extends State<SimpleS3Test> {
  File selectedFile;

  bool isLoading = false;
  bool uploaded = false;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: new Text(
          "Simple S3 Test",
        ),
      ),
      body: Center(
        child: selectedFile != null
            ? isLoading ? CircularProgressIndicator() : Image.file(selectedFile)
            : GestureDetector(
                onTap: () async {
                  File _file = await FilePicker.getFile(type: FileType.image);
                  setState(() {
                    selectedFile = _file;
                  });
                },
                child: Icon(
                  Icons.add,
                  size: 30,
                ),
              ),
      ),
      floatingActionButton: !isLoading
          ? FloatingActionButton(
              backgroundColor: uploaded ? Colors.green : Colors.blue,
              child: Icon(
                uploaded ? Icons.delete : Icons.arrow_upward,
                color: Colors.white,
              ),
              onPressed: () async {
                if (uploaded) {
//                  print(await SimpleS3.delete(filePath, bucketName, poolID, AWSRegions.apSouth1, debugLog: true));
                  setState(() {
                    selectedFile = null;
                    uploaded = false;
                  });
                }
                if (selectedFile != null) _upload();
              },
            )
          : null,
    );
  }

  Future<String> _upload() async {
    String result;

    if (result == null) {
      try {
        setState(() {
          isLoading = true;
        });
//        String result = await SimpleS3.uploadFile(selectedFile, bucketName, poolID, AWSRegions.apSouth1,
//            debugLog: true, s3FolderPath: "test", accessControl: S3AccessControl.publicRead);

        setState(() {
          uploaded = true;
          isLoading = false;
        });
      } catch (e) {
        print(e);
      }
    }
    return result;
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  simple_s3: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:simple_s3/simple_s3.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
50
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:simple_s3/simple_s3.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:simple_s3/simple_s3.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:simple_s3/simple_s3.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:simple_s3/simple_s3.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • simple_s3 that is a package requiring null.

Health suggestions

Format lib/simple_s3.dart.

Run flutter format to format lib/simple_s3.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
mime_type ^0.3.1 0.3.2
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test