Playframework 播放框架,上传后不显示图像
我有以下问题。我上传一张图片并将其保存在images文件夹中。上传后我想显示上传的图片,但它不工作,为什么?如果我重新启动应用程序,上传的图像将显示出来。为什么?HTML我使用“class=”img responsive“> 图像路径: GET/images/*file controllers.Assets.at(path=“/public/images”,file)Playframework 播放框架,上传后不显示图像,playframework,playframework-2.0,Playframework,Playframework 2.0,我有以下问题。我上传一张图片并将其保存在images文件夹中。上传后我想显示上传的图片,但它不工作,为什么?如果我重新启动应用程序,上传的图像将显示出来。为什么?HTML我使用“class=”img responsive“> 图像路径: GET/images/*file controllers.Assets.at(path=“/public/images”,file) 这是一个安全问题。在大多数情况下,在开发模式下,您可以看到上载的文件,但在生产模式下,您无法看到 解决方案是实现一个自定义控制器
这是一个安全问题。在大多数情况下,在开发模式下,您可以看到上载的文件,但在生产模式下,您无法看到 解决方案是实现一个自定义控制器,可以直接从磁盘写入/读取文件。或者使用另一个应用服务器来提供照片,即。 存在外部资产控制器,但在生产模式下禁用 $.html
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");
}
}
}