Wednesday, 21 January 2015

Android Example to upload file to Amazon S3 Bucket



Amazon S3

Amazon Simple Storage Service is storage for the Internet. It is designed to make web-scale computing easier for developers.
Amazon S3 has a simple web services interface that you can use to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefits on to developers.
Buckets
A bucket is a container for objects stored in Amazon S3. Every object is contained in a bucket. Buckets serve several purposes: they organize the Amazon S3 namespace at the highest level, they identify the account responsible for storage and data transfer charges, they play a role in access control, and they serve as the unit of aggregation for usage reporting.
Steps to upload a file to Amazon S3 Bucket

·         Create an instance of the AmazonS3Client.

·         Execute one of the AmazonS3Client.putObject overloads depending on whether you are uploading data from a file, or a stream.
·         Amazon S3 credentials are needed i.e Access Key and Secret Key which are given by account holder
·         Amazon S3 Bucket name is needed which is created by the account holder
AmazonS3 s3client = new AmazonS3Client(new BasicAWSCredentials("access_key","secret_key"));
try {
System.out.println("Uploading a new object to S3 from a file\n");
File file = new File(uploadFileName);
s3client.putObject(new PutObjectRequest(bucketName, "folder/"+keyName, file));
} catch (AmazonServiceException ase) {
System.out.println("Caught an AmazonServiceException”);
} catch (AmazonClientException ace) {
System.out.println("Caught an AmazonClientException”);
}
}

3 comments:

  1. Appium training in Chennai
    We provide best appium training in Chennai with real time scenarios. For real time training reach us 8122241286 and become experts in appium.
    Appium training in chennai

    ReplyDelete
  2. Really nice blog post. provided a helpful information. I hope that you will post

    more updates like this
    AWS Online Training

    ReplyDelete

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...