mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-10-03 22:45:15 +08:00
文件上传完成后跳转到文件详情页
This commit is contained in:
@@ -123,8 +123,8 @@
|
|||||||
<button id="beginUpload" disabled="true">开始上传</button>
|
<button id="beginUpload" disabled="true">开始上传</button>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<input type="checkbox" id="checkbox-auto-upload" checked="true">
|
<input type="checkbox" id="checkbox-auto-upload"><!-- checked -->
|
||||||
<label for="checkbox-auto-upload">连续上传(上传完成后留在本页)</label>
|
<label for="checkbox-auto-upload" style="font-size: small;">连续上传(上传完成后留在本页)</label>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<script src="/assets/lib/crypto-js/sha1.js"></script>
|
<script src="/assets/lib/crypto-js/sha1.js"></script>
|
||||||
@@ -372,9 +372,9 @@
|
|||||||
var status = axiosData.status;
|
var status = axiosData.status;
|
||||||
var data = axiosData.data;
|
var data = axiosData.data;
|
||||||
if (status === "success") {
|
if (status === "success") {
|
||||||
console.log(data);
|
console.log("data", data);
|
||||||
// 取得预授权URL,使用该URL进行文件上传
|
// 取得预授权URL,使用该URL进行文件上传
|
||||||
uploadFile(file, data.url);
|
uploadFile(file, data.url, data.fileId);
|
||||||
} else {
|
} else {
|
||||||
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
|
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
|
||||||
}
|
}
|
||||||
@@ -387,7 +387,7 @@
|
|||||||
//##############################################
|
//##############################################
|
||||||
//传入预授权 URL ,将文件上传到这个地址
|
//传入预授权 URL ,将文件上传到这个地址
|
||||||
//##############################################
|
//##############################################
|
||||||
function uploadFile(file, preSignedUrl) {
|
function uploadFile(file, preSignedUrl, fileId) {
|
||||||
// refer: https://cloud.tencent.com/document/product/436/35651
|
// refer: https://cloud.tencent.com/document/product/436/35651
|
||||||
|
|
||||||
// 获取到 Url 后,前端可以这样 ajax 上传
|
// 获取到 Url 后,前端可以这样 ajax 上传
|
||||||
@@ -412,7 +412,8 @@
|
|||||||
if ($("#checkbox-auto-upload").is(":checked")) {
|
if ($("#checkbox-auto-upload").is(":checked")) {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
} else {
|
} else {
|
||||||
location.href = "<%= pageUrl %>../";
|
// location.href = "<%= pageUrl %>../";
|
||||||
|
location.href = "<%= pageUrl %>../detail?id=" + fileId;
|
||||||
}
|
}
|
||||||
}, 300);
|
}, 300);
|
||||||
};
|
};
|
||||||
|
@@ -286,13 +286,18 @@ public class FileController extends BaseController {
|
|||||||
// 判断对象是否存在
|
// 判断对象是否存在
|
||||||
Boolean isExist = qCloudCosUtils.doesObjectExist(bookSaveFolder, fileSha1);
|
Boolean isExist = qCloudCosUtils.doesObjectExist(bookSaveFolder, fileSha1);
|
||||||
String url = null;
|
String url = null;
|
||||||
|
Map resultMap = new HashMap();
|
||||||
|
resultMap.put("guid", urlGUID);
|
||||||
switch (httpMethodName) {
|
switch (httpMethodName) {
|
||||||
case PUT:
|
case PUT:
|
||||||
// 上传文件
|
// 上传文件
|
||||||
if (isExist) throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "文件已存在");
|
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);
|
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);
|
url = qCloudCosUtils.generatePresignedUrl(userModel.getId(), httpMethodName, bookSaveFolder, fileSha1, expireMinute, urlGUID);
|
||||||
break;
|
break;
|
||||||
case GET:
|
case GET:
|
||||||
@@ -310,10 +315,8 @@ public class FileController extends BaseController {
|
|||||||
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "httpMethod 参数暂不支持");
|
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "httpMethod 参数暂不支持");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map map = new HashMap();
|
resultMap.put("url", url);
|
||||||
map.put("url", url);
|
return CommonReturnType.create(resultMap);
|
||||||
map.put("guid", urlGUID);
|
|
||||||
return CommonReturnType.create(map);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -123,14 +123,14 @@ public class FileObjectServiceImpl implements FileObjectService {
|
|||||||
* @param fileNameWithoutExt 文件名(不包含扩展名)
|
* @param fileNameWithoutExt 文件名(不包含扩展名)
|
||||||
* @param fileStorageMediumEnum 文件存储介质
|
* @param fileStorageMediumEnum 文件存储介质
|
||||||
* @param bookOrigin 文件来源
|
* @param bookOrigin 文件来源
|
||||||
* @return 是否插入成功
|
* @return 返回文件Id
|
||||||
* @throws InvocationTargetException
|
* @throws InvocationTargetException
|
||||||
* @throws IllegalAccessException
|
* @throws IllegalAccessException
|
||||||
* @throws BusinessException
|
* @throws BusinessException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@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 fileExt, String fileNameWithoutExt, FileStorageMediumEnum fileStorageMediumEnum,
|
||||||
String bookOrigin, Long lastModified
|
String bookOrigin, Long lastModified
|
||||||
) throws InvocationTargetException, IllegalAccessException, BusinessException {
|
) throws InvocationTargetException, IllegalAccessException, BusinessException {
|
||||||
@@ -189,7 +189,7 @@ public class FileObjectServiceImpl implements FileObjectService {
|
|||||||
if (!isSuccess) {
|
if (!isSuccess) {
|
||||||
throw new BusinessException(BusinessErrorCode.UNKNOWN_ERROR, "文件对象创建失败");
|
throw new BusinessException(BusinessErrorCode.UNKNOWN_ERROR, "文件对象创建失败");
|
||||||
}
|
}
|
||||||
return true;
|
return fileId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -55,7 +55,7 @@ public interface FileObjectService {
|
|||||||
* @throws BusinessException
|
* @throws BusinessException
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改文件对象上传状态信息
|
* 修改文件对象上传状态信息
|
||||||
|
Reference in New Issue
Block a user