Image processing 玩图像大小调整会导致旧文件存储在服务器上

Image processing 玩图像大小调整会导致旧文件存储在服务器上,image-processing,playframework,Image Processing,Playframework,我想将上传的图像调整为小版本和缩略图版本。因此,我使用的是很棒的S3模块。这工作正常,所有图像都上传到s3。 但在上传了几次之后,我意识到大小调整后的图像也存储在磁盘上,不会被删除 我的代码: public static Picture save(File file, Recipe recipe){ File picture = new File(UUID.randomUUID().toString()); //Resize main picture Images.re

我想将上传的图像调整为小版本和缩略图版本。因此,我使用的是很棒的S3模块。这工作正常,所有图像都上传到s3。 但在上传了几次之后,我意识到大小调整后的图像也存储在磁盘上,不会被删除

我的代码:

public static Picture save(File file, Recipe recipe){

    File picture = new File(UUID.randomUUID().toString());
    //Resize main picture
    Images.resize(file, picture, 600, 600, true);

    File thumbNail = new File(UUID.randomUUID().toString());
    //Resize thumbnail
    Images.resize(file, thumbNail, 260, 190, true);

    Picture pic = new Picture();
    pic.pictureFileName = file.getName();
    pic.picture = new S3Blob();

    pic.thumbPictureFileName = file.getName();
    pic.thumbPicture = new S3Blob();

    pic.recipe = recipe;
    try{
        pic.picture.set(new FileInputStream(picture), MimeTypes.getContentType(file.getName()));
        pic.thumbPicture.set(new FileInputStream(thumbNail), MimeTypes.getContentType(file.getName()));
        pic.save();

    }catch(FileNotFoundException e){
        Logger.error(e, "FileNotFound");
    }

    return pic;
}

上传后如何删除文件?正常情况下,我会在流结束时等待它,但我不知道它什么时候结束,因此我无法删除该文件。

正如Samuel评论的那样,我希望出现一种不正确的异步行为


调整大小并上传图片后,只需使用file.delete()将其删除即可

如何推断S3存储操作是异步的?你为什么不把这些文件存储到一个临时目录中呢?