摘要:Java PlayFramework Upadload and Download
html
<form action="/Controller/upload" id="frm" method="POST" accept-charset="utf-8" enctype="multipart/form-data" >
<input type="file" name="data_file">
<input type="submit" name="submit" value="送出">
下載檔案位置<a target="_blank" href="${file_path}">下載檔案</a>
</form>
controller
public static void upload(File data_file)
{
String file_path = "";
if(data_file!=null)
{
String file_content = FileUtils.readFileToString(data_file,"utf-8");
FileUtils.writeStringToFile(Play.getFile("/public/data/files/"+data_file.getName()),file_content,"utf-8");
file_path = "/public/data/files/"+data_file.getName();
}
render(file_path);
}