I am trying to load multiple files at the same time with Play 2 and build some thumbnails for them with asynchronous api. Uploading is work quite ok and great troubles come when image processing starts. The problem is as follows(a bit of desciption): files, which were fetched from request and collected into list are disappearing while image processing(take a lot of time).
And some samples here:
//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)
);
}
}
)
);
}
So
gallery.addItem(item);
takes a lot of time, and next call for
Logger.debug("picFile: " + picFile.exists());
says that picFile do not exists. I know, this is because those files are temporary... but should they exists emm a little bit longer? And the question is: how to solve this trouble. Should I look at temporary files in java?