If you want to implement file upload to AWS S3 as part of your Android app here are some tips to get you going.
// Create a new S3Client with your credentials. You could get the Keys from the IAM console.
Setup
- Download the Android-AWS SDK
- Unzip the downloaded package then go to the lib folder
- In the lib folder copy aws-android-sdk-[version]-core.jar and aws-android-sdk-[version]-s3.jar
- Use the mechanism your IDE has provided add these jar files and make it available in code. (For Android Studio 0.5.4, I manually added it to the app > lib folder and right clicked on the jar files and select Make Module
Coding
// Create a new S3Client with your credentials. You could get the Keys from the IAM console.
AmazonS3Client s3Client =
new AmazonS3Client(new BasicAWSCredentials("ACCESS KEY", "SECRET KEY");
// Create a PutObjectRequest. This is used to communicate with AWS and upload your file
// The KEY is the full file path to where your file should be stored on AWS.
// For example, images/category/subcategory/image_name.jpg
// The FILE is a file object that you want to upload
PutObjectRequest putObjectRequest = new PutObjectRequest("BUCKET", "KEY", "FILE");
// Now tell AWS S3 a that you want to upload an image with the specifications above.
s3Client.putObject(putObjectRequest);
// The KEY is the full file path to where your file should be stored on AWS.
// For example, images/category/subcategory/image_name.jpg
// The FILE is a file object that you want to upload
PutObjectRequest putObjectRequest = new PutObjectRequest("BUCKET", "KEY", "FILE");
// Now tell AWS S3 a that you want to upload an image with the specifications above.
s3Client.putObject(putObjectRequest);
No comments:
Post a Comment