| | |
| | | */ |
| | | public final static String CLOUD_STORAGE_CONFIG_KEY = "sys.oss.cloudStorageService"; |
| | | |
| | | public final static String DEFAULT_CONTENT_TYPE = "application/octet-stream"; |
| | | |
| | | |
| | | } |
| | |
| | | package com.ruoyi.oss.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.oss.constant.CloudConstant; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.enumd.CloudServiceEnumd; |
| | | import com.ruoyi.oss.enumd.PolicyType; |
| | |
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | |
| | | minioClient.putObject(PutObjectArgs.builder() |
| | | .bucket(properties.getBucketName()) |
| | | .object(path) |
| | | .contentType(StrUtil.blankToDefault(contentType, CloudConstant.DEFAULT_CONTENT_TYPE)) |
| | | .contentType(StrUtil.blankToDefault(contentType, MediaType.APPLICATION_OCTET_STREAM_VALUE)) |
| | | .stream(inputStream, inputStream.available(), -1) |
| | | .build()); |
| | | } catch (Exception e) { |
| | |
| | | package com.ruoyi.system.controller; |
| | | |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.annotation.RepeatSubmit; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.constraints.NotEmpty; |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | return AjaxResult.success(map); |
| | | } |
| | | |
| | | @ApiOperation("ä¸è½½OSSäºåå¨") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:download')") |
| | | @GetMapping("/download/{ossId}") |
| | | public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException { |
| | | SysOss sysOss = iSysOssService.getById(ossId); |
| | | if (sysOss == null) { |
| | | throw new CustomException("æä»¶æ°æ®ä¸åå¨!"); |
| | | } |
| | | response.reset(); |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8"); |
| | | long data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false); |
| | | response.setContentLength(Convert.toInt(data)); |
| | | } |
| | | |
| | | /** |
| | | * å é¤OSSäºåå¨ |
| | | */ |
| | |
| | | }) |
| | | } |
| | | |
| | | // ä¸ä¼ OSSäºåå¨ |
| | | export function addOss(data) { |
| | | return request({ |
| | | url: '/system/oss/upload', |
| | | method: 'post', |
| | | data: data |
| | | }) |
| | | } |
| | | |
| | | // ä¸è½½OSSäºåå¨ |
| | | export function downloadOss(ossId) { |
| | | return request({ |
| | | url: '/system/oss/download/' + ossId, |
| | | method: 'get' |
| | | }) |
| | | } |
| | | |
| | | // å é¤OSSäºåå¨ |
| | | export function delOss(ossId) { |
| | | return request({ |
| | |
| | | }, |
| | | data() { |
| | | return { |
| | | uploadUrl: process.env.VUE_APP_BASE_API + "/common/upload", // ä¸ä¼ çå¾çæå¡å¨å°å |
| | | uploadUrl: process.env.VUE_APP_BASE_API + "/system/oss/upload", // ä¸ä¼ çå¾çæå¡å¨å°å |
| | | headers: { |
| | | Authorization: "Bearer " + getToken() |
| | | }, |
| | |
| | | <!-- æä»¶å表 --> |
| | | <transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul"> |
| | | <li :key="file.uid" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in fileList"> |
| | | <el-link :href="`${baseUrl}${file.url}`" :underline="false" target="_blank"> |
| | | <el-link :href="`${file.url}`" :underline="false" target="_blank"> |
| | | <span class="el-icon-document"> {{ getFileName(file.name) }} </span> |
| | | </el-link> |
| | | <div class="ele-upload-list__item-content-action"> |
| | |
| | | data() { |
| | | return { |
| | | baseUrl: process.env.VUE_APP_BASE_API, |
| | | uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // ä¸ä¼ çå¾çæå¡å¨å°å |
| | | uploadFileUrl: process.env.VUE_APP_BASE_API + "/system/oss/upload", // ä¸ä¼ çå¾çæå¡å¨å°å |
| | | headers: { |
| | | Authorization: "Bearer " + getToken(), |
| | | }, |
| | |
| | | dialogVisible: false, |
| | | hideUpload: false, |
| | | baseUrl: process.env.VUE_APP_BASE_API, |
| | | uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // ä¸ä¼ çå¾çæå¡å¨å°å |
| | | uploadImgUrl: process.env.VUE_APP_BASE_API + "/system/oss/upload", // ä¸ä¼ çå¾çæå¡å¨å°å |
| | | headers: { |
| | | Authorization: "Bearer " + getToken(), |
| | | }, |
| | |
| | | // ç¶åå°æ°ç»è½¬ä¸ºå¯¹è±¡æ°ç» |
| | | this.fileList = list.map(item => { |
| | | if (typeof item === "string") { |
| | | if (item.indexOf(this.baseUrl) === -1) { |
| | | item = { name: this.baseUrl + item, url: this.baseUrl + item }; |
| | | } else { |
| | | item = { name: item, url: item }; |
| | | } |
| | | item = { name: item, url: item }; |
| | | } |
| | | return item; |
| | | }); |
| | |
| | | }, |
| | | // ä¸ä¼ æååè° |
| | | handleUploadSuccess(res) { |
| | | this.fileList.push({ name: res.data.fileName, url: res.data.fileName }); |
| | | this.fileList.push({ name: res.data.fileName, url: res.data.url }); |
| | | this.$emit("input", this.listToString(this.fileList)); |
| | | this.loading.close(); |
| | | }, |
¶Ô±ÈÐÂÎļþ |
| | |
| | | import axios from 'axios' |
| | | import { getToken } from '@/utils/auth' |
| | | |
| | | const mimeMap = { |
| | | oss: 'application/octet-stream' |
| | | } |
| | | |
| | | const baseUrl = process.env.VUE_APP_BASE_API |
| | | export function downLoadOss(ossId, filename) { |
| | | var url = baseUrl + '/system/oss/download/' + ossId |
| | | axios({ |
| | | method: 'get', |
| | | url: url, |
| | | responseType: 'blob', |
| | | headers: { 'Authorization': 'Bearer ' + getToken() } |
| | | }).then(res => { |
| | | resolveBlob(res, mimeMap.oss, filename) |
| | | }) |
| | | } |
| | | /** |
| | | * è§£æblobååºå
容并ä¸è½½ |
| | | * @param {*} res blobååºå
容 |
| | | * @param {String} mimeType MIMEç±»å |
| | | */ |
| | | export function resolveBlob(res, mimeType, filename) { |
| | | const aLink = document.createElement('a') |
| | | var blob = new Blob([res.data], { type: mimeType }) |
| | | aLink.href = URL.createObjectURL(blob) |
| | | aLink.setAttribute('download', filename) // 设置ä¸è½½æä»¶åç§° |
| | | document.body.appendChild(aLink) |
| | | aLink.click() |
| | | document.body.removeChild(aLink); |
| | | } |
| | |
| | | plain |
| | | icon="el-icon-plus" |
| | | size="mini" |
| | | @click="handleAdd" |
| | | @click="handleFile" |
| | | v-hasPermi="['system:oss:upload']" |
| | | >ä¸ä¼ </el-button> |
| | | >ä¸ä¼ æä»¶</el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button |
| | | type="primary" |
| | | plain |
| | | icon="el-icon-plus" |
| | | size="mini" |
| | | @click="handleImage" |
| | | v-hasPermi="['system:oss:upload']" |
| | | >ä¸ä¼ å¾ç</el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button |
| | |
| | | <el-table-column label="äºåå¨ä¸»é®" align="center" prop="ossId" v-if="false"/> |
| | | <el-table-column label="æä»¶å" align="center" prop="fileName" /> |
| | | <el-table-column label="åå" align="center" prop="originalName" /> |
| | | <el-table-column label="æä»¶åç¼å" align="center" prop="fileSuffix" /> |
| | | <el-table-column label="URLå°å" align="center" prop="url" /> |
| | | <el-table-column label="æä»¶åç¼" align="center" prop="fileSuffix" /> |
| | | <el-table-column label="æä»¶å±ç¤º" align="center" prop="url" > |
| | | <template slot-scope="scope"> |
| | | <el-image |
| | | v-if="scope.row.fileSuffix.indexOf('png','jpg','jpeg') > 0" |
| | | style="width: 100px; height: 100px;" |
| | | :src="scope.row.url" |
| | | :preview-src-list="[scope.row.url]"/> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="å建æ¶é´" align="center" prop="createTime" width="180"> |
| | | <template slot-scope="scope"> |
| | | <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span> |
| | |
| | | <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> |
| | | <el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
| | | <el-form-item label="æä»¶å"> |
| | | <imageUpload v-model="form.file"/> |
| | | <fileUpload v-model="form.file" v-if="type === 0"/> |
| | | <imageUpload v-model="form.file" v-if="type === 1"/> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div slot="footer" class="dialog-footer"> |
| | |
| | | </template> |
| | | |
| | | <script> |
| | | import { listOss, delOss, addOss, downloadOss } from "@/api/system/oss"; |
| | | import { listOss, delOss } from "@/api/system/oss"; |
| | | import { downLoadOss } from "@/utils/ossdownload"; |
| | | |
| | | export default { |
| | | name: "Oss", |
| | |
| | | ossList: [], |
| | | // å¼¹åºå±æ é¢ |
| | | title: "", |
| | | // å¼¹åºå±æ é¢ |
| | | type: 0, |
| | | // æ¯å¦æ¾ç¤ºå¼¹åºå± |
| | | open: false, |
| | | // å建æ¶é´æ¶é´èå´ |
| | |
| | | // 表åéç½® |
| | | reset() { |
| | | this.form = { |
| | | ossId: undefined, |
| | | file: undefined, |
| | | fileName: undefined, |
| | | originalName: undefined, |
| | | fileSuffix: undefined, |
| | | url: undefined, |
| | | createTime: undefined, |
| | | createBy: undefined, |
| | | updateTime: undefined, |
| | | updateBy: undefined, |
| | | service: undefined |
| | | }; |
| | | this.resetForm("form"); |
| | | }, |
| | |
| | | this.single = selection.length!==1 |
| | | this.multiple = !selection.length |
| | | }, |
| | | /** æ°å¢æé®æä½ */ |
| | | handleAdd() { |
| | | /** æä»¶æé®æä½ */ |
| | | handleFile() { |
| | | this.reset(); |
| | | this.open = true; |
| | | this.title = "ä¸ä¼ OSSäºåå¨"; |
| | | this.title = "ä¸ä¼ æä»¶"; |
| | | this.type = 0; |
| | | }, |
| | | /** å¾çæé®æä½ */ |
| | | handleImage() { |
| | | this.reset(); |
| | | this.open = true; |
| | | this.title = "ä¸ä¼ å¾ç"; |
| | | this.type = 1; |
| | | }, |
| | | /** æäº¤æé® */ |
| | | submitForm() { |
| | | this.$refs["form"].validate(valid => { |
| | | if (valid) { |
| | | this.buttonLoading = true; |
| | | addOss(this.form).then(response => { |
| | | this.msgSuccess("ä¸ä¼ æå"); |
| | | this.open = false; |
| | | this.getList(); |
| | | }).finally(() => { |
| | | this.buttonLoading = false; |
| | | }); |
| | | } |
| | | }); |
| | | this.open = false; |
| | | this.getList(); |
| | | }, |
| | | /** ä¸è½½æé®æä½ */ |
| | | handleDownload(row) { |
| | | downLoadOss(row.ossId, row.originalName) |
| | | }, |
| | | /** å é¤æé®æä½ */ |
| | | handleDelete(row) { |
| | |
| | | |
| | | insert into sys_menu values('1600', 'æä»¶æ¥è¯¢', '118', '1', '#', '', 1, 0, 'F', '0', '0', 'system:oss:query', '#', 'admin', sysdate(), '', null, ''); |
| | | insert into sys_menu values('1601', 'æä»¶ä¸ä¼ ', '118', '2', '#', '', 1, 0, 'F', '0', '0', 'system:oss:upload', '#', 'admin', sysdate(), '', null, ''); |
| | | insert into sys_menu values('1602', 'æä»¶å é¤', '118', '3', '#', '', 1, 0, 'F', '0', '0', 'system:oss:remove', '#', 'admin', sysdate(), '', null, ''); |
| | | insert into sys_menu values('1602', 'æä»¶ä¸è½½', '118', '3', '#', '', 1, 0, 'F', '0', '0', 'system:oss:download', '#', 'admin', sysdate(), '', null, ''); |
| | | insert into sys_menu values('1603', 'æä»¶å é¤', '118', '4', '#', '', 1, 0, 'F', '0', '0', 'system:oss:remove', '#', 'admin', sysdate(), '', null, ''); |