grails - ImageScalr + Grails + AWS插件

标签 grails amazon-s3 image-resizing image-scaling

我试图实现一些图片上传到我的网络应用程序。
我遇到的问题是,我试图使用Imagescalr创建原始照片的缩略图,而我正在使用AWS Plugin将它们上传到我的存储桶中。
因此,我的代码如下:(删除的验证和不影响问题/可能答案的内容)

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? 

因此,问题/问题将在代码中进行解释,希望有人知道该怎么做。提前致谢。

最佳答案

在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()

}

关于grails - ImageScalr + Grails + AWS插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19065539/

相关文章:

java - 如何从 Amazon elastic map reduce 中的映射器访问文件内容?

java - Android 应用程序中的云驱动器使用

c# - 从 System.Drawing.Image 在文件系统上创建一个新图像?

grails - 无法在 grails 中运行 cucumber

javascript - grails中的错误管理

java - 使用适用于 Amazon S3 存储桶的 Java 开发工具包下载大量文件

c++ - 未填充到 4 字节的 3 channel 图像重采样?

php - 按需或上传时调整图像大小更好吗?

grails - 如何在 Grails 中实现空间(地理位置)搜索?

Grails - 子类中的唯一约束