文件上传
集成
<!--若已引过则无需重复引-->
<dependency>
<groupId>com.manatee.manatee-lowcode</groupId>
<artifactId>lowcode-file</artifactId>
<version>${lowcode.version}</version>
</dependency>
信息
需上传文件的接口的 url 需要特殊处理,需要把modularity
替换为 modularityUpload
,如: /biz/modularityUpload
/project176/excelUpload
支持多文件上传
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
@RequestMapping(path = "/modularityUpload/project{projectId}/{code}", method = RequestMethod.POST)
@ResponseBody
public JSONObject doModularityUpload(@RequestParam(value = FILE, required = false) MultipartFile file,
@RequestParam(value = "files", required = false) List<MultipartFile> files,
HttpServletRequest request,@PathVariable Long projectId,@PathVariable String code){
ProcessContent content=new ProcessContent();
try{
if(file==null&&files==null){
throw new BizException(ResultCode.PARAM_IS_ERROR,"上传文件不能为空");
}
initParam(content,request);
content.putTempContent(ProcessConstant.Key.CODE,code);
content.putTempContent(ProcessConstant.Key.PROJECT_ID,projectId);
if(file!=null){
content.setFile(file.getInputStream());
content.setFileName(file.getOriginalFilename());
content.putRequest("manateeFilename",file.getOriginalFilename());
}
if(files!=null){
List<ProcessFileInfo> processFileInfos=files.stream().map(item->{
ProcessFileInfo processFileInfo=new ProcessFileInfo();
try{
processFileInfo.setInputStream(item.getInputStream());
}catch(IOException e){
throw new RuntimeException(e);
}
processFileInfo.setFileName(item.getOriginalFilename());
return processFileInfo;
}).collect(Collectors.toList());
content.setFiles(processFileInfos);
}
JSONObject result=customizeModuleManager.customize(request,content);
return result;
}catch(Throwable e){
e.printStackTrace();
content.addException(e);
}
WebResult result=WebUtil.wirteResult(content);
return result.toJson();
}
OSS文件上传
项目配置
oss:
endpoint: xxx
accessKeyId: xxx
secretAccessKey: xxx
ownDomain: xxx
配置说明
配置项 | 说明 |
---|---|
Bucket | 要上传到的oss BucketName |
文件夹 | 文件夹名称,如:testFolder |
结果对象名 | 返回结果名称 |
在返回中显示 | 是否将返回值输出到返回结果 |
本地上传
填入对应的信息,即可完成文件上传 文件夹目录:/uploadFile/file