在S3上存储时如何重定向图像?

时间:2014-08-13 03:29:58

标签: java image amazon-s3 playframework-2.0 multipartform-data

我在S3上存储图像以用于电子邮件。当我在电子邮件中查看图像时,会旋转一些图像。我使用AmazonS3Client上传,并在Play2应用中使用MultipartFormData上传图片,如下所示:

    Http.MultipartFormData body = request().body().asMultipartFormData();
    String[] pics = new String[]{"picture1", "picture2", "picture3"};
    String[] fileNames = new String[3];
    for(int i = 0; i < pics.length; i++) {
        Http.MultipartFormData.FilePart picture = body.getFile(pics[i]);

        if (picture != null) {
            String fileName = picture.getFilename();
            play.Logger.info("fileName: " + fileName);
            File file = picture.getFile();

            String existingBucketName = "yadayadayada";
            String keyName = UUID.randomUUID().toString();

            PutObjectRequest putObjectRequest = new PutObjectRequest(existingBucketName, keyName + "-" + fileName, file);
            putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); // public for all
            s3Client.putObject(putObjectRequest);
            fileNames[i] = "https://s3.amazonaws.com/yadayadayada/" + keyName + "-" + fileName;
        }
    }

0 个答案:

没有答案