I am trying to upload a file to S3 using Scala Playframe work 2.4.1
Specifically using the module play-s3 7.0.2
I can get it to work for text files but when I try and upload an image I get this message, The provided 'x-amz-content-sha256' header does not match what was computed.
If I swap "avatar.jpeg" for "text.txt" and "image/jpeg" for "plain/text" in the following code it works. The text file gets uploaded to S3. But if I try and upload an image (I've tried jpeg and png) it fails saying the header doesn't match. I have no idea what I am doing wrong at this point and it is driving me nuts.
import fly.play.s3.{BucketFile, S3, S3Exception}
import java.nio.file.{Files, Paths}
def test() = Action
{ implicit request =>
val file_path = "/path/to/file/avatar.jpeg"
val bucket = S3("path_to_bucket")
val byte_array = Files.readAllBytes(Paths.get(file_path))
val result = bucket + BucketFile("avatar.jpeg", "image/jpeg", byte_array)
result.map { unit =>
Logger.info("Saved the file")
}
.recover {
case S3Exception(status, code, message, originalXml) =>
{
Logger.info("Error: " + message)
Logger.info("originalXml: " + originalXml)
}
}
Ok("Yay")
}
The solution to this is to not use play 2.4.1. There is something wrong with the hashing of binary data with 2.4.1. 2.4.2 works just fine though.