I have the following problem. I upload an image an save it in images folder. After upload i would like to display the uploaded image, but it not work why? If I restart the application the uploaded images would display. Why ? HTML I use " class="img-responsive">
Image Route:
GET /images/*file controllers.Assets.at(path="/public/images", file)
public class ImagePublicService extends Controller{
public static Result upload() {
MultipartFormData body = request().body().asMultipartFormData();
FilePart picture = body.getFile("file");
play.Logger.debug("File: "+ body);
if (picture != null) {
String fileName = picture.getFilename();
String extension = fileName.substring(fileName.indexOf("."));
String uuid = uuid=java.util.UUID.randomUUID().toString();
fileName = uuid + extension;
play.Logger.debug("Image: " + fileName);
String contentType = picture.getContentType();
File file = picture.getFile();
try {
File newFile = new File("public/images", fileName);
FileUtils.moveFile(file,newFile );
play.Logger.debug("File moved");
} catch (IOException ioe) {
System.out.println("Problem operating on filesystem");
}
play.Logger.debug("File uploaded");
ObjectNode result = Json.newObject();
result.put("src", "images/" + fileName);
return ok(result);
} else {
play.Logger.debug("File not uploaded");
flash("error", "Missing file");
return badRequest("Fehler");
}
}
}