我在Amazon S3服务器上上传图片时遇到了一些麻烦,我的目标是:
我的应用正确创建了图片,并要求用户保存图片;在JS库的帮助下
但问题是:
我自己的想法,
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.
答案 0 :(得分:2)
嗯,我找到了答案,并且很有信心,这篇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)
}