1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-21 01:10:39 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

文件上传完成后跳转到文件详情页

This commit is contained in:
2022-04-19 23:42:46 +08:00
parent febee45fc9
commit e3e3191fde
4 changed files with 19 additions and 15 deletions

View File

@@ -123,8 +123,8 @@
<button id="beginUpload" disabled="true">开始上传</button>
<p>
<input type="checkbox" id="checkbox-auto-upload" checked="true">
<label for="checkbox-auto-upload">连续上传(上传完成后留在本页)</label>
<input type="checkbox" id="checkbox-auto-upload"><!-- checked -->
<label for="checkbox-auto-upload" style="font-size: small;">连续上传(上传完成后留在本页)</label>
</p>
<script src="/assets/lib/crypto-js/sha1.js"></script>
@@ -372,9 +372,9 @@
var status = axiosData.status;
var data = axiosData.data;
if (status === "success") {
console.log(data);
console.log("data", data);
// 取得预授权URL使用该URL进行文件上传
uploadFile(file, data.url);
uploadFile(file, data.url, data.fileId);
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
@@ -387,7 +387,7 @@
//##############################################
//传入预授权 URL ,将文件上传到这个地址
//##############################################
function uploadFile(file, preSignedUrl) {
function uploadFile(file, preSignedUrl, fileId) {
// refer: https://cloud.tencent.com/document/product/436/35651
// 获取到 Url 后,前端可以这样 ajax 上传
@@ -412,7 +412,8 @@
if ($("#checkbox-auto-upload").is(":checked")) {
window.location.reload();
} else {
location.href = "<%= pageUrl %>../";
// location.href = "<%= pageUrl %>../";
location.href = "<%= pageUrl %>../detail?id=" + fileId;
}
}, 300);
};

View File

@@ -286,13 +286,18 @@ public class FileController extends BaseController {
// 判断对象是否存在
Boolean isExist = qCloudCosUtils.doesObjectExist(bookSaveFolder, fileSha1);
String url = null;
Map resultMap = new HashMap();
resultMap.put("guid", urlGUID);
switch (httpMethodName) {
case PUT:
// 上传文件
if (isExist) throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "文件已存在");
fileObjectService.uploadFile(fileId, fileName, bookSaveFolder + fileSha1, fileSize,
Integer realFileId = fileObjectService.uploadFile(fileId, fileName, bookSaveFolder + fileSha1, fileSize,
fileSha1, fileExt, fileName, FileStorageMediumEnum.QCLOUD_COS, "", lastModified);
// fileId 可能为 0 (创建新文件)
// realFileId 是从数据库中查询出来的真实的文件id
resultMap.put("fileId", realFileId);
url = qCloudCosUtils.generatePresignedUrl(userModel.getId(), httpMethodName, bookSaveFolder, fileSha1, expireMinute, urlGUID);
break;
case GET:
@@ -310,10 +315,8 @@ public class FileController extends BaseController {
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "httpMethod 参数暂不支持");
}
Map map = new HashMap();
map.put("url", url);
map.put("guid", urlGUID);
return CommonReturnType.create(map);
resultMap.put("url", url);
return CommonReturnType.create(resultMap);
}
/**

View File

@@ -123,14 +123,14 @@ public class FileObjectServiceImpl implements FileObjectService {
* @param fileNameWithoutExt 文件名(不包含扩展名)
* @param fileStorageMediumEnum 文件存储介质
* @param bookOrigin 文件来源
* @return 是否插入成功
* @return 返回文件Id
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws BusinessException
*/
@Override
@Transactional
public Boolean uploadFile(Integer fileId, String fileName, String filePath, Long fileSize, String fileSHA1,
public Integer uploadFile(Integer fileId, String fileName, String filePath, Long fileSize, String fileSHA1,
String fileExt, String fileNameWithoutExt, FileStorageMediumEnum fileStorageMediumEnum,
String bookOrigin, Long lastModified
) throws InvocationTargetException, IllegalAccessException, BusinessException {
@@ -189,7 +189,7 @@ public class FileObjectServiceImpl implements FileObjectService {
if (!isSuccess) {
throw new BusinessException(BusinessErrorCode.UNKNOWN_ERROR, "文件对象创建失败");
}
return true;
return fileId;
}
/**

View File

@@ -55,7 +55,7 @@ public interface FileObjectService {
* @throws BusinessException
*/
@Transactional
Boolean uploadFile(Integer fileId, String fileName, String filePath, Long fileSize, String fileSHA1, String fileExt, String fileNameWithoutExt, FileStorageMediumEnum fileStorageMediumEnum, String bookOrigin, Long lastModified) throws InvocationTargetException, IllegalAccessException, BusinessException;
Integer uploadFile(Integer fileId, String fileName, String filePath, Long fileSize, String fileSHA1, String fileExt, String fileNameWithoutExt, FileStorageMediumEnum fileStorageMediumEnum, String bookOrigin, Long lastModified) throws InvocationTargetException, IllegalAccessException, BusinessException;
/**
* 修改文件对象上传状态信息