【发布时间】:2012-07-02 06:57:42
【问题描述】:
我正在尝试使用 Play 2 同时加载多个文件,并使用异步 api 为它们构建一些缩略图。 上传工作还不错,但在图像处理开始时会遇到很大的麻烦。 问题如下(有点描述):从请求中获取并收集到列表中的文件在图像处理时消失了(需要很多时间)。
这里还有一些示例:
//part of controller
public static Result addPictures2(Long galleryId) {
MultipartFormData body = request().body().asMultipartFormData();
final List<FilePart> fileList = body.getFiles();
final Long fGalleryId = galleryId;
Promise<Boolean> promiseOfBool = Akka.future(
new Callable<Boolean>() {
public Boolean call() {
Gallery gallery = Gallery.find.byId(fGalleryId);
for(FilePart part : fileList) {
File picFile = part.getFile();
Logger.debug("picFile: " + picFile.exists());
String extension = FilenameUtils.getExtension(part.getFilename());
GalleryItem item = new GalleryItem("", "", picFile, extension);
gallery.addItem(item);
}
gallery.update();
return true;
}
}
);
return async(
promiseOfBool.map(
new Function<Boolean, Result>() {
public Result apply(Boolean b) {
return redirect(
controllers.backend.routes.GalleryContentController.showGalleryItemsPage(fGalleryId)
);
}
}
)
);
}
所以
gallery.addItem(item);
需要很多时间,下次调用
Logger.debug("picFile:" + picFile.exists());
说 picFile 不存在。我知道,这是因为这些文件是临时的……但是它们应该存在更长时间吗?问题是:如何解决这个麻烦。我应该查看 java 中的临时文件吗?
【问题讨论】: