0

我正在尝试将一些图片上传到我的 webapp。我遇到的问题是我试图使用 Imagecalr 创建原始照片的缩略图,并且我使用 AWS 插件将它们上传到我的存储桶。所以,我的代码如下:(删除的验证和不影响问题/可能答案的东西)

def uploadPic() {
def f = request.getFile('file')
.   
.
.       
def s3file = f.inputStream.s3upload(filename) { //this is for the normal photo
            path "POI/ID/"
    }

def imageIn = ImageIO.read(???); //Dont know if I can put the f file here as parameter... do I have to store it somewhere first, call the s3 file, or I can resize on - the - fly?
BufferedImage scaledImage = Scalr.resize(imageIn, 150);



//Here I should upload the thumb. How can I call something like what is done for the normal photo? 

因此,问题/问题在代码中进行了解释,希望有人知道如何做到这一点。提前致谢。

4

1 回答 1

2

在 Grails 中,request.getFile() 不返回 java.io.File 对象。您可以使用输入流来写出一个文件,但我可能会做这样的事情,尽管我会使用服务并将事情进一步分解。但这应该让您朝着正确的方向开始。考虑这更像是一个伪代码工作流建议。

def uploadPic() {

   def f = request.getFile('file')
   def tempFile = new File('/some/local/dir/myImage.png') 
   f.transferTo(tempFile)

   // upload the original image to S3
   whateverApi.s3Upload(tempFile)

   def bufferedImage = ImageIO.read(tempFile)
   def scaledBufferedImage = Scalr.resize(bufferedImage, 150)

   // write the scaledImg to disk
   def scaledImage = new File('/some/local/dir/myImage-150.png');
   ImageIO.write(scaledBufferedImage, "png", scaledImage);

   //upload scaled image to S3
   whateverApi.s3Upload(scaledImage)

   // clean up
   tempFile.delete()
   scaledImage.delete()

}
于 2013-09-28T18:56:16.703 回答