Storing files on Amazon S3 using Scala

Table of contents
Reading Time: 2 minutes

Amazon S3 serves the purpose of “storage for the Internet” . S3 stand for ” Simple Storage Service”. Amazon S3 can be used for storing and retrieving any amount of data at any time, from anywhere on the web. You can use simple interface “AWS Management Console” provided by Amazon for creating buckets for storage , adding files in those buckets and for many other tasks.

Here you’ll get the idea about storing the files on Amazon S3 using Scala and how we can make all items “public” within a bucket.

You have to include the dependency below for using Amazon S3.

This code snippet would help you to create a bucket and store the items in that bucket on Amazon S3.
You’d find your “AWS Access Key” & “AWS_Security_Key” in the “Security Credential” option of your Amazon S3 account.

In order to make the files in a bucket Public , you have to write the policy for that bucket. This policy would make all the items publicly accessible within a bucket. You’d find the option of adding a policy in the properties option of a bucket.

2 thoughts on “Storing files on Amazon S3 using Scala2 min read

  1. Hi Neelkanth,

    You can make your files public without write a policy. I could do this with the following code:

    // …. add these classes to be imported
    import com.amazonaws.services.s3.model.{CannedAccessControlList, PutObjectRequest}

    // …. create aws credentials and s3client object
    val objectRequest:PutObjectRequest = new PutObjectRequest(“BUCKET_NAME”,”FILE_PATH”, file);
    objectRequest.setCannedAcl(CannedAccessControlList.PublicRead);

    // Instead upload using amazonS3Client.putObject(bucketName, “FileName”, fileToUpload), use just you PutObjectRequest object
    amazonS3Client.putObject(objectSettings)

  2. beginner question:
    What does this mean/how to do it?

    “You have to include the dependency below for using Amazon S3.”

Comments are closed.