ruoyi-oss/src/main/java/com/ruoyi/oss/entity/UploadResult.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-oss/src/main/java/com/ruoyi/oss/enumd/CloudServiceEnumd.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-oss/src/main/java/com/ruoyi/system/controller/SysOssController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-ui/src/utils/ossdownload.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-ui/src/views/system/oss/index.vue | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
ruoyi-oss/src/main/java/com/ruoyi/oss/entity/UploadResult.java
@@ -6,6 +6,8 @@ /** * 上传返回体 * * @author Lion Li */ @Data @NoArgsConstructor ruoyi-oss/src/main/java/com/ruoyi/oss/enumd/CloudServiceEnumd.java
@@ -9,7 +9,7 @@ /** * 云存储服务商枚举 * * @author LionLi * @author Lion Li */ @Getter @AllArgsConstructor ruoyi-oss/src/main/java/com/ruoyi/system/controller/SysOssController.java
@@ -10,6 +10,7 @@ import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.exception.CustomException; import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.system.bo.SysOssQueryBo; import com.ruoyi.system.domain.SysOss; import com.ruoyi.system.service.ISysOssService; @@ -29,6 +30,8 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotEmpty; import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -88,6 +91,9 @@ throw new CustomException("文件数据不存在!"); } response.reset(); response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); FileUtils.setAttachmentResponseHeader(response, URLEncoder.encode(sysOss.getOriginalName(), StandardCharsets.UTF_8)); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8"); long data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false); response.setContentLength(Convert.toInt(data)); ruoyi-ui/src/utils/ossdownload.js
@@ -6,7 +6,7 @@ } const baseUrl = process.env.VUE_APP_BASE_API export function downLoadOss(ossId, filename) { export function downLoadOss(ossId) { var url = baseUrl + '/system/oss/download/' + ossId axios({ method: 'get', @@ -14,7 +14,7 @@ responseType: 'blob', headers: { 'Authorization': 'Bearer ' + getToken() } }).then(res => { resolveBlob(res, mimeMap.oss, filename) resolveBlob(res, mimeMap.oss) }) } /** @@ -22,11 +22,17 @@ * @param {*} res blob响应内容 * @param {String} mimeType MIME类型 */ export function resolveBlob(res, mimeType, filename) { export function resolveBlob(res, mimeType) { const aLink = document.createElement('a') var blob = new Blob([res.data], { type: mimeType }) // 从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名; var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*') var contentDisposition = decodeURI(res.headers['content-disposition']) var result = patt.exec(contentDisposition) var fileName = result[1] fileName = fileName.replace(/\"/g, '') aLink.href = URL.createObjectURL(blob) aLink.setAttribute('download', filename) // 设置下载文件名称 aLink.setAttribute('download', decodeURI(fileName)) // 设置下载文件名称 document.body.appendChild(aLink) aLink.click() document.body.removeChild(aLink); ruoyi-ui/src/views/system/oss/index.vue
@@ -289,7 +289,7 @@ }, /** 下载按钮操作 */ handleDownload(row) { downLoadOss(row.ossId, row.originalName) downLoadOss(row.ossId) }, /** 删除按钮操作 */ handleDelete(row) {