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.3.2
Follow @ab_hi_j on Twitter
Features
| Feature |
Description |
| Null Safe |
:white_check_mark: |
| Upload Percentage |
:white_check_mark: |
| Supports all files |
SimpleS3 auto detects content type of file by looking into extension |
| Set Access Type |
Allows you to set access type of file ex. PublicRead, Private etc Default is Public Read |
| Timestamp |
Turned 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 Name |
Allows to change name of file about to upload. Note : File name must contain extension. |
| Custom S3 folder path |
Allows to upload file to specific folder in S3 |
| Sub Region Support |
Allows upload/delete operations on S3 having sub regions |
| Delete Object |
Allows deletion of file object |
| Auto Generates URL |
URL pointing to S3 file is auto generated.
|
Not working in Android Release mode ?
If your Android app is not working in release mode please check this section
Usage Examples
Simple File Upload
SimpleS3 _simpleS3 = SimpleS3();
String result = await _simpleS3.uploadFile(
file, <--------------- Selected File
bucketName, <--------- Your Bucket Name
poolID, <------------- Your POOL ID
AWSRegions.apSouth1 <- S3 server region
);
Delete
bool result = await SimpleS3.delete(
filePath, <---------------- S3 File Path
bucketName, <-------------- Your Bucket Name
poolID, <------------------ Your POOL ID
AWSRegions.apSouth1, <----- S3 server region
);
File Upload with Percentage
SimpleS3 _simpleS3 = SimpleS3();
String result = await _simpleS3.uploadFile(
file, <--------------- Selected File
bucketName, <--------- Your Bucket Name
poolID, <------------- Your POOL ID
AWSRegions.apSouth1 <- S3 server region
);
child: StreamBuilder<dynamic>(
stream: _simpleS3.getUploadPercentage,
builder: (context, snapshot) {
return new Text(
snapshot.data != null ? "Uploaded: ${snapshot.data}" : "Simple S3",
);
}),
Custom File Name
SimpleS3 _simpleS3 = SimpleS3();
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
SimpleS3 _simpleS3 = SimpleS3();
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
);
Setting Access Control
SimpleS3 _simpleS3 = SimpleS3();
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**
);
Using Timestamp
SimpleS3 _simpleS3 = SimpleS3();
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
);
SimpleS3 _simpleS3 = SimpleS3();
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
);
Using Sub-Region
SimpleS3 _simpleS3 = SimpleS3();
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
SimpleS3 _simpleS3 = SimpleS3();
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
);
Android Proguard settings for release mode
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-aws-2.1.5.pro'
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-aws-2.1.5.pro'
}
}
Now copy contents of this file proguard-aws-2.1.5.pro
Create a new file with name "proguard-aws-2.1.5.pro" at the same location as app/build.gradle and paste the copied contents into this file.
Your release mode APK should work now.