//上传资料类型音频文件
@At("/upload")
@Ok("json")
@AdaptBy(type = UploadAdaptor.class,args = { "${app.root}/WEB-INF/wavTmp", "8192", "UTF-8", "20000" })
public NutMap upload( ...
默认文件路径是:
\WEB-INF\wavTmp\00\00\00\00\00\00\00\01.wav
文件夹太深了
//上传资料类型音频文件
@At("/upload")
@Ok("json")
@AdaptBy(type = UploadAdaptor.class,args = { "${app.root}/WEB-INF/wavTmp", "8192", "UTF-8", "20000" })
public NutMap upload( ...
默认文件路径是:
\WEB-INF\wavTmp\00\00\00\00\00\00\00\01.wav
文件夹太深了
代码如下:
//上传资料类型音频文件
@At("/upload")
@Ok("json")
@AdaptBy(type = UploadAdaptor.class,args = { "${app.root}/WEB-INF/wavTmp", "8192", "UTF-8", "20000" })
public NutMap upload(
@Param("Filedata") TempFile f,
HttpServletRequest req,
ServletContext context, @Param("stationTypeIdHidden") int stationtypeid) throws SQLException, IOException {
Path newFile = Paths.get(f.getFile().getPath());
String copiedFilePath=Mvcs.getServletContext().getRealPath("/")+"wavUploads\\"+f.getFile().getName();
Path copiedFile = Paths.get(copiedFilePath);
try {
Files.copy(newFile, copiedFile, StandardCopyOption.REPLACE_EXISTING);
System.out.println("File copied successfully!");
} catch (IOException e) {
e.printStackTrace();
}
String wavPath=copiedFilePath;
wavPath=wavPath.substring(wavPath.indexOf("\\wavUploads\\"),wavPath.length());
StationType stationType=dao.fetch(StationType.class, stationtypeid);
stationType.setWavPath(wavPath);
dao.update(stationType);
String msg="上传成功!";
return NutMap.NEW().addv("msg", msg);
}
每次改动文件 保存的音频文件就没了
大大您说的"不过,放在webcontent下不是很好的,放在项目外的一个路径比较好,读取的时候通过入口方法走"
应该放在哪里合适 ? 比如 "c:\wavUploads\ ??