【问题标题】:Get image data from Html5 canvas and upload it to Amazon S3 server, using Scala使用 Scala 从 Html5 画布获取图像数据并将其上传到 Amazon S3 服务器
【发布时间】:2014-07-08 04:51:45
【问题描述】:

我在 Amazon S3 服务器上上传图片有点麻烦,我的目标是:

  • 在 Html5 画布上通过拖放图像在其中创建图像,
  • 然后将图像上传/保存到 Amazon S3 服务器中。

我的应用程序正确创建了图像,并要求用户保存图像;在 JS 库的帮助下

但问题是:

  • 我需要将它们直接保存到 S3 服务器,而不是我的本地。我一直在使用 java-aws sdk。

我自己的想法,

  • 我可以将图像保存在本地计算机上,然后使用 java-aws-sdk 上传,但这将是一个较长的过程,即保存在本地然后上传到 s3 服务器。

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.

【问题讨论】:

标签: html scala canvas amazon-s3


【解决方案1】:

好吧,我找到了答案,这篇 SO 帖子 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)
    }

【讨论】:

  • 虽然我对 ObjectMetadata 以及将编码字符串获取到我的 Scala 方法、Ajax 之类的东西有很多需要研究,但现在它似乎工作了!!
猜你喜欢
  • 2014-09-01
  • 2015-05-30
  • 2010-12-08
  • 1970-01-01
  • 2017-09-18
  • 1970-01-01
  • 1970-01-01
  • 2014-06-26
  • 2012-07-04
相关资源
最近更新 更多