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.

3

1 Answer 1

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)
    }
Sign up to request clarification or add additional context in comments.

1 Comment

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!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.