1

I am in a bit of trouble with uploading images on Amazon S3 servers,my objective goes like:

  • Create image on Html5 canvas by dragging and dropping images in it,
  • Then upload/save the image in Amazon S3 server.

My app properly creates the image, and asks the user to save the image; with the help of JS libraries

But the problem:

  • I need to save them directly to S3 server, not on my local. I have been using java-aws sdk.

My own ideas,

  • I could save the image on my local machine, and then upload using the java-aws-sdk but that would be a longer process i.e. saving in local and then uploading in s3 server.

Is there any way to get the image-data or image to backend scala code and then converting it into some image obj (since java-aws seems to need a file to upload) and then I would be using java-aws sdk for the rest.

mane
  • 1,149
  • 16
  • 41
  • 1
    Checkout this link [Uploading Image to Amazon s3 ][1] may be it will help you. [1]: http://stackoverflow.com/questions/11240127/uploading-image-to-amazon-s3-with-html-javascript-jquery-with-ajax-request-n?rq=1 – Pulkit Agarwal May 20 '14 at 04:46
  • My problem is I would not be using forms.... http://stackoverflow.com/questions/934012/get-image-data-in-javascript – mane May 20 '14 at 05:50
  • Have you seen the page about [body parsers](http://www.playframework.com/documentation/2.3.x/ScalaBodyParsers) ? You can find some examples of that on the web. These are not mine, I just found them on manning forum: [1](https://github.com/mslinn/AwsS3) [2](https://github.com/mslinn/play21-file-upload-streaming) – goral May 20 '14 at 05:58

1 Answers1

2

Well i found my answer and much credit goes to this SO post, Get image data in JavaScript?

def foo(source: String) {
        //Getting the base64 encoded string, then converting into byte stream
        val imgByte = Base64.decodeBase64(source)
        val bis = new ByteArrayInputStream(imgByte)

        val bucketName = "SOME_BUCKET"
        val AWS_ACCESS_KEY = "KEY"   
        val AWS_SECRET_KEY = "SECRET"

        val yourAWSCredentials = new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY)
        val amazonS3Client = new AmazonS3Client(yourAWSCredentials)
        val md = new ObjectMetadata

        amazonS3Client.putObject(bucketName, "fireside2.png", bis, md)
    }
Community
  • 1
  • 1
mane
  • 1,149
  • 16
  • 41
  • though I have got much to research on the ObjectMetadata and getting the encoded string to my Scala method, Ajax and stuff ...., but for now it seems to work!! – mane May 20 '14 at 08:36