我们在使用e签宝电子合同的时候,需要上传电子合同,但是官方是要求上传的是文件流,有的时候我们将文件上传到minio或者其他文件存储系统,如何实现合同上传呢?
思路:可以将网络文件下载到服务器,然后获取文件流上传,上传成功后,再讲文件删除即可。
上传电子合同
@PostMapping("/uploadContract")
@ApiOperation(value = "上传合同", notes = "传入contract")
public R uploadContract(@Valid @RequestBody ContractVO contract) throws Exception {
String path = "";
path = contract.getFilesUrl();//合同地址
String filename = path.substring(path.lastIndexOf("/") + 1, path.length());
// ----------------正式------------------
path = path.replace("https://minio.haoapochn.cn", "");
//获取服务器minio文件路径,获取文件流
String filePath = "/data/minio" + path;
FileInputStream file = new FileInputStream(filePath);
if (file != null) {
String contractId = EqbUtil.getUploadUrl(filePath, filename, corporation.getEsignAppId(), corporation.getEsignSecret());
String[] su = contractId.split(";");
if (!su[0].equals("0")) {
return R.fail("创建电子合同失败");
} else {
contract.setFid(su[1]);
}
} else { // 否则,转型失败
throw new Exception();
}
contract.setCreateUser(getUser().getUserId());
contract.setCreateDept(Long.valueOf(getUser().getDeptId()));
contract.setSigners(contract.getCustomerId().toString());
if (contract.getCustomerIdb() != null) {
contract.setSigners(contract.getCustomerId() + "," + contract.getCustomerIdb());
}
contractService.save(contract);
return R.success(contract.getId() + "");
}