0
我正在使用Play Framework 2.0.4。這裏是我試過的代碼:將圖像存儲到本地系統的指定位置
public static Result save() throws FileNotFoundException {
Form<Tenant> tenantForm = form(Tenant.class).bindFromRequest();
Form<Ten> tenForm = form(Ten.class).bindFromRequest();
Long tenantid = tenForm.get().tenant_id;
Http.MultipartFormData body = request().body().asMultipartFormData();
Http.MultipartFormData.FilePart picture = body.getFile("logo_url");
if (picture != null) {
String fileName = picture.getFilename();
String contentType = picture.getContentType();
File file = picture.getFile();
tenantForm.get().logo_url = file.getPath();
tenantForm.get().save();
return redirect(
routes.Application.index()
);
} else {
flash("error", "Missing file");
return redirect(
routes.Project.ctstenant(0,"name","asc","","",tenantid)
);
}
}
它會將圖像存儲在臨時文件夾中。我希望它存儲在指定的文件夾中。隨着例子將不勝感激。
感謝您的幫助。
爲什麼不把文件從temp移動到你想要的位置? – Carsten 2013-04-24 11:19:37