给下面代码添加注释:else { try { log.info("DocumentServiceImpl breakpointUpload, upfile=[{}], chunkNumber=[{}], totalChunks=[{}], identifier=[{}], documentId=[{}], folderId=[{}], versionId=[{}]", new Object[]{file.getOriginalFilename(), chunkNumber, totalChunks, identifier, documentId, folderId, versionId}); double checkFileSize = (double)file.getSize() / 1048576.0; if (checkFileSize > this.maxbreakpointUploadFileSize) { throw new BimdcException(file.getOriginalFilename() + "文件大小不能超过" + this.maxbreakpointUploadFileSize + "M!"); } else { Map<String, Object> params = new HashMap(9); params.put("chunkNumber", chunkNumber); params.put("totalChunks", totalChunks); params.put("identifier", identifier); if (null != documentId) { params.put("documentId", documentId); } if (null != folderId) { params.put("folderId", folderId); } if (null != versionId) { params.put("versionId", versionId); } String url = this.serviceUrl + "document/v1/document/document/uploadResume"; String result = this.httpMultipartFormdata.postMultipartFile(url, params, file, "upfile"); log.info("upload result = [{}]", result); Document document = new Document(); if (result.contains("code")) { JSONObject jsonObject = JSONObject.fromObject(result); if ("0".equals(jsonObject.get("code"))) { jsonObject = JSONObject.fromObject(JSONObject.fromObject(result).get("data")); document.setDocumentId(jsonObject.getString("pathMd5")); document.setFileId(jsonObject.getString("id")); document.setVersionNo(Integer.parseInt(jsonObject.getString("updateNo"))); } } return document;
时间: 2024-04-28 15:22:30 浏览: 98
// 这段代码是一个方法,方法名为 breakpointUpload,参数列表中包括文件对象 file,以及一些标识符 identifier、documentId、folderId、versionId 等等
else {
// 注意,这个 else 是与上面的 if 相对应的,表示 file 不为空的情况
try {
// 记录一些信息,用于调试和记录日志
log.info("DocumentServiceImpl breakpointUpload, upfile=[{}], chunkNumber=[{}], totalChunks=[{}], identifier=[{}], documentId=[{}], folderId=[{}], versionId=[{}]", new Object[]{file.getOriginalFilename(), chunkNumber, totalChunks, identifier, documentId, folderId, versionId});
// 计算文件大小,判断是否超过最大上传文件大小,如果超过则抛出异常
double checkFileSize = (double)file.getSize() / 1048576.0;
if (checkFileSize > this.maxbreakpointUploadFileSize) {
throw new BimdcException(file.getOriginalFilename() + "文件大小不能超过" + this.maxbreakpointUploadFileSize + "M!");
} else {
// 如果文件大小没问题,则构造一个参数列表,用于传递给接口
Map<String, Object> params = new HashMap(9);
params.put("chunkNumber", chunkNumber);
params.put("totalChunks", totalChunks);
params.put("identifier", identifier);
if (null != documentId) {
params.put("documentId", documentId);
}
if (null != folderId) {
params.put("folderId", folderId);
}
if (null != versionId) {
params.put("versionId", versionId);
}
// 构造接口的 URL,然后调用上传文件的方法,将文件和参数一起上传,得到上传结果
String url = this.serviceUrl + "document/v1/document/document/uploadResume";
String result = this.httpMultipartFormdata.postMultipartFile(url, params, file, "upfile");
// 记录上传结果,用于调试和记录日志
log.info("upload result = [{}]", result);
// 解析上传结果,将一些信息封装到 Document 对象中,然后返回
Document document = new Document();
if (result.contains("code")) {
JSONObject jsonObject = JSONObject.fromObject(result);
if ("0".equals(jsonObject.get("code"))) {
jsonObject = JSONObject.fromObject(JSONObject.fromObject(result).get("data"));
document.setDocumentId(jsonObject.getString("pathMd5"));
document.setFileId(jsonObject.getString("id"));
document.setVersionNo(Integer.parseInt(jsonObject.getString("updateNo")));
}
}
return document;
}
}
}
阅读全文