不能引入云存储方案。因为内网部署。,要传2g的视频上去,代码如下
7 回复
@AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/WEB-INF/tmp", "8192", "utf-8" })
@At("/file")
@Ok("json")
public Object uploadFile(@Param("file") TempFile tmpFile, HttpServletRequest req) {
Map<String, Object> data = new HashMap<String, Object>();
try {
File fromFile = tmpFile.getFile();
String tmpName = tmpFile.getSubmittedFileName();
String fileName = generateFileName(tmpName);
File toFile = new File(uploadPath+fileName);
if(!toFile.exists()){
toFile.getParentFile().mkdirs();
toFile.createNewFile();
}
copyFile(fromFile, toFile);
data.put("fileName", fileName.replaceAll("\\\\", "/"));
data.put("orginName", tmpName);
Attachment attachment = new Attachment();
attachment.setFileName(fileName);
attachment.setFileOriginalName(tmpName);
attachment.setUserName(getUser().getLoginname());
attachment.setUploadIp(getUser().getLoginIp());
attachment.setFileExtName(getFileType(fileName));
attachment.setFilePath(uploadPath+fileName);
attachment.setFileSize(getFileSize(tmpFile));
attachment.setUrl(downloadUrl+"?name="+fileName.replaceAll("\\\\", "/"));
attachmentService.insert(attachment);
return Result.success("system.upload.success", data);
} catch (IOException e) {
e.printStackTrace();
return Result.error("system.upload.error");
}
}
有什么好的解决方案吗。。这个是用formdata上传的 为啥会导致页面有点卡啊??是因为上传的时候导致占用了大量浏览器内存的原因吗?
添加回复
请先登陆