标签:oss sftp require box bst div 封装 font ftp
<div class="easyui-layout" style="width:100%;height:100%;">
<div data-options="region:‘west‘,split:true" style="width:100%;">
<form class="form-horizontal" id="fileform" name="fileform" method="post" enctype="multipart/form-data" action="applyLoans/submitphone" style="margin: 0;padding: 10px" >
<div class="col-md-12" style="margin-bottom: 20px">
<label class="easylabel lb-70" >选择文件<font color="#FF0000">*</font></label>
<input id="file_url" name="file_url" buttonText="选择文件" required="true" class="easyui-filebox" type="file" style="filewidth: 100%">
</div>
<input type="submit" value="sss"/>
</form>
</div>
</div>
/**
* 封装上传方法
*
* @param request
* @param loanId
* @return
* @throws Exception
*/
public Map<String, Object> upload(MultipartHttpServletRequest request, int loanId) throws Exception {
String filePath = "";
String osskey = "";
Map<String, Object> map = new HashMap<>();
//提取上传文件
Map<String, MultipartFile> files = request.getFileMap();
//判断是否含有文件上传控件
if (files.size() > 0) {
//定义可以上传文件的类型
List<String> filelimit = Arrays.asList("jpg", "gif", "png");
Map<String, String> filelimitmap = new HashMap<>();
filelimit.forEach((s) -> filelimitmap.put(s, s));
Set<String> keys = files.keySet();
//遍历集合
for (String key : keys) {
//判断为多文件上传
List<MultipartFile> fileList = request.getFiles(key);
//判断是否有文件
if (fileList.size() == 0) {
continue;
}
StringBuilder str = new StringBuilder();
String filename = "";
//遍历集合上传文件
for (MultipartFile file : fileList) {
//判断是否有文件
if (file.getOriginalFilename().length() <= 1) {
continue;
}
int id = 0;
//判断是否为限制的文件格式
filename = file.getOriginalFilename();
int lastIndexOf = filename.lastIndexOf(".");
String s = filename.substring(lastIndexOf + 1);
if (filelimitmap.get(s) == null) {
continue;
}
//1.放oss上返回key
osskey = OSS.uploadImage(file.getInputStream());
//2.放sftp返回一个路径 再存入file_data
filePath = SFTP.addFile(file.getInputStream(), loanId, file.getOriginalFilename(), osskey);
map.put("osskey", osskey); //阿里云oss key
map.put("filePath", filePath); //sftp返回的路径
map.put("fileName", filename);
map.put("ext", s);
id = adminDao.submitFileData(map);
System.out.println("返回的id" + id);
str.append(id + ",");
}
String strid = "" + str;
map.put(key, strid);
}
}
return map;
}
标签:oss sftp require box bst div 封装 font ftp
原文地址:https://www.cnblogs.com/zhou-tt/p/12100830.html