update 编写 Minio 实现 调整OSS模块结构
| | |
| | | exit 1 |
| | | } |
| | | |
| | | #å¼å¯æéç«¯å£ |
| | | #å¼å¯æé端å£(ç产ç¯å¢ä¸æ¨èå¼å¯) |
| | | port(){ |
| | | # mysql ç«¯å£ |
| | | firewall-cmd --add-port=3306/tcp --permanent |
| | | # redis ç«¯å£ |
| | | firewall-cmd --add-port=6379/tcp --permanent |
| | | # minio api ç«¯å£ |
| | | firewall-cmd --add-port=9000/tcp --permanent |
| | | # minio æ§å¶å°ç«¯å£ |
| | | firewall-cmd --add-port=9001/tcp --permanent |
| | | # éå¯é²ç«å¢ |
| | | service firewalld restart |
| | | } |
| | | |
| | |
| | | |
| | | #å¯å¨åºç¡æ¨¡å |
| | | base(){ |
| | | docker-compose up -d mysql nginx-web redis |
| | | docker-compose up -d mysql nginx-web redis minio |
| | | } |
| | | |
| | | #å¯å¨åºç¡æ¨¡å |
| | |
| | | - /docker/mysql/data/:/var/lib/mysql/ |
| | | # é
ç½®æè½½ |
| | | - /docker/mysql/conf/:/etc/mysql/conf.d/ |
| | | # ä¸»æºæ¬æºæ¶é´æä»¶æ å° ä¸æ¬æºæ¶é´åæ¥ |
| | | - /etc/localtime:/etc/localtime:ro |
| | | command: |
| | | # å°mysql8.0é»è®¤å¯ç çç¥ ä¿®æ¹ä¸º åå
çç¥ (mysql8.0对å
¶é»è®¤çç¥åäºæ´æ¹ ä¼å¯¼è´å¯ç æ æ³å¹é
) |
| | | --default-authentication-plugin=mysql_native_password |
| | |
| | | - /docker/redis/conf/redis.conf:/redis.conf:rw |
| | | # æ°æ®æä»¶ |
| | | - /docker/redis/data:/data:rw |
| | | # ä¸»æºæ¬æºæ¶é´æä»¶æ å° ä¸æ¬æºæ¶é´åæ¥ |
| | | - /etc/localtime:/etc/localtime:ro |
| | | command: "redis-server --appendonly yes" |
| | | privileged: true |
| | | restart: always |
| | |
| | | ruoyi_net: |
| | | ipv4_address: 172.30.0.48 |
| | | |
| | | minio: |
| | | image: minio/minio:RELEASE.2021-07-08T01-15-01Z |
| | | hostname: "minio" |
| | | ports: |
| | | # api ç«¯å£ |
| | | - 9000:9000 |
| | | # æ§å¶å°ç«¯å£ |
| | | - 9001:9001 |
| | | environment: |
| | | # 管çåå°ç¨æ·å |
| | | MINIO_ACCESS_KEY: ruoyi |
| | | # 管çåå°å¯ç ï¼æå°8个å符 |
| | | MINIO_SECRET_KEY: ruoyi123 |
| | | volumes: |
| | | # æ å°å½åç®å½ä¸çdataç®å½è³å®¹å¨å
/dataç®å½ |
| | | - /docker/minio/data:/data |
| | | # æ å°é
ç½®ç®å½ |
| | | - /docker/minio/config:/root/.minio/ |
| | | # ä¸»æºæ¬æºæ¶é´æä»¶æ å° ä¸æ¬æºæ¶é´åæ¥ |
| | | - /etc/localtime:/etc/localtime:ro |
| | | command: server --console-address ':9001' /data # æå®å®¹å¨ä¸çç®å½ /data |
| | | privileged: true |
| | | restart: always |
| | | networks: |
| | | ruoyi_net: |
| | | ipv4_address: 172.30.0.54 |
| | | |
| | | ruoyi-server1: |
| | | image: "ruoyi/ruoyi-server:2.5.1" |
| | | environment: |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.oss.entity; |
| | | |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.experimental.Accessors; |
| | | |
| | | /** |
| | | * ä¸ä¼ è¿åä½ |
| | | */ |
| | | @Data |
| | | @NoArgsConstructor |
| | | @Accessors(chain = true) |
| | | public class UploadResult { |
| | | |
| | | /** |
| | | * æä»¶è·¯å¾ |
| | | */ |
| | | private String url; |
| | | |
| | | /** |
| | | * æä»¶å |
| | | */ |
| | | private String filename; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | /* |
| | | * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * Neither the name of the dreamlu.net developer nor the names of its |
| | | * contributors may be used to endorse or promote products derived from |
| | | * this software without specific prior written permission. |
| | | * Author: Chill åºéª (smallchill@163.com) |
| | | */ |
| | | package com.ruoyi.oss.enumd; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * minioçç¥é
ç½® |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum PolicyType { |
| | | |
| | | /** |
| | | * åªè¯» |
| | | */ |
| | | READ("read-only"), |
| | | |
| | | /** |
| | | * åªå |
| | | */ |
| | | WRITE("write-only"), |
| | | |
| | | /** |
| | | * 读å |
| | | */ |
| | | READ_WRITE("read-write"); |
| | | |
| | | /** |
| | | * ç±»å |
| | | */ |
| | | private final String type; |
| | | |
| | | } |
| | |
| | | public static class MinioProperties { |
| | | |
| | | /** |
| | | * ä¸çç»å®çåå |
| | | * minioåå |
| | | */ |
| | | private String endpoint; |
| | | |
| | | /** |
| | | * ä¸çè·¯å¾åç¼ |
| | | */ |
| | | private String prefix; |
| | | |
| | | /** |
| | | * ä¸çACCESS_KEY |
| | | * minio ACCESS_KEY |
| | | */ |
| | | private String accessKey; |
| | | |
| | | /** |
| | | * ä¸çSECRET_KEY |
| | | * minio SECRET_KEY |
| | | */ |
| | | private String secretKey; |
| | | |
| | | /** |
| | | * ä¸çåå¨ç©ºé´å |
| | | * minio åå¨ç©ºé´å |
| | | */ |
| | | private String bucketName; |
| | | |
| | |
| | | private String prefix; |
| | | |
| | | /** |
| | | * è
¾è®¯äºappId |
| | | */ |
| | | private String appId; |
| | | |
| | | /** |
| | | * è
¾è®¯äºSecretId |
| | | */ |
| | | private String secretId; |
| | |
| | | package com.ruoyi.oss.service; |
| | | |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | |
| | | import java.io.InputStream; |
| | | |
| | | /** |
| | |
| | | * @param path æä»¶è·¯å¾ï¼å
嫿件å |
| | | * @return è¿åhttpå°å |
| | | */ |
| | | String upload(byte[] data, String path); |
| | | UploadResult upload(byte[] data, String path); |
| | | |
| | | /** |
| | | * æä»¶å é¤ |
| | |
| | | * @param suffix åç¼ |
| | | * @return è¿åhttpå°å |
| | | */ |
| | | String uploadSuffix(byte[] data, String suffix); |
| | | UploadResult uploadSuffix(byte[] data, String suffix); |
| | | |
| | | /** |
| | | * æä»¶ä¸ä¼ |
| | |
| | | * @param path æä»¶è·¯å¾ï¼å
嫿件å |
| | | * @return è¿åhttpå°å |
| | | */ |
| | | String upload(InputStream inputStream, String path); |
| | | UploadResult upload(InputStream inputStream, String path); |
| | | |
| | | /** |
| | | * æä»¶ä¸ä¼ |
| | |
| | | * @param suffix åç¼ |
| | | * @return è¿åhttpå°å |
| | | */ |
| | | String uploadSuffix(InputStream inputStream, String suffix); |
| | | UploadResult uploadSuffix(InputStream inputStream, String suffix); |
| | | } |
| | |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.service.ICloudStorageService; |
| | | import org.springframework.beans.factory.InitializingBean; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public abstract String upload(byte[] data, String path); |
| | | public abstract UploadResult upload(byte[] data, String path); |
| | | |
| | | @Override |
| | | public abstract void delete(String path); |
| | | |
| | | @Override |
| | | public String upload(InputStream inputStream, String path) { |
| | | public UploadResult upload(InputStream inputStream, String path) { |
| | | byte[] data = IoUtil.readBytes(inputStream); |
| | | return this.upload(data, path); |
| | | } |
| | | |
| | | @Override |
| | | public abstract String uploadSuffix(byte[] data, String suffix); |
| | | public abstract UploadResult uploadSuffix(byte[] data, String suffix); |
| | | |
| | | @Override |
| | | public abstract String uploadSuffix(InputStream inputStream, String suffix); |
| | | public abstract UploadResult uploadSuffix(InputStream inputStream, String suffix); |
| | | |
| | | @Override |
| | | public abstract void afterPropertiesSet() throws Exception; |
| | |
| | | import com.aliyun.oss.ClientConfiguration; |
| | | import com.aliyun.oss.OSSClient; |
| | | import com.aliyun.oss.common.auth.DefaultCredentialProvider; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.enumd.CloudServiceEnumd; |
| | | import com.ruoyi.oss.exception.OssException; |
| | | import com.ruoyi.oss.factory.OssFactory; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String upload(byte[] data, String path) { |
| | | public UploadResult upload(byte[] data, String path) { |
| | | return upload(new ByteArrayInputStream(data), path); |
| | | } |
| | | |
| | | @Override |
| | | public String upload(InputStream inputStream, String path) { |
| | | public UploadResult upload(InputStream inputStream, String path) { |
| | | try { |
| | | client.putObject(this.properties.getBucketName(), path, inputStream); |
| | | } catch (Exception e) { |
| | | throw new OssException("ä¸ä¼ æä»¶å¤±è´¥ï¼è¯·æ£æ¥é
置信æ¯"); |
| | | } |
| | | return this.properties.getEndpoint() + "/" + path; |
| | | return new UploadResult().setUrl(properties.getEndpoint() + "/" + path).setFilename(path); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String uploadSuffix(byte[] data, String suffix) { |
| | | public UploadResult uploadSuffix(byte[] data, String suffix) { |
| | | return upload(data, getPath(this.properties.getPrefix(), suffix)); |
| | | } |
| | | |
| | | @Override |
| | | public String uploadSuffix(InputStream inputStream, String suffix) { |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix) { |
| | | return upload(inputStream, getPath(this.properties.getPrefix(), suffix)); |
| | | } |
| | | |
| | |
| | | package com.ruoyi.oss.service.impl; |
| | | |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.enumd.CloudServiceEnumd; |
| | | import com.ruoyi.oss.enumd.PolicyType; |
| | | import com.ruoyi.oss.exception.OssException; |
| | | import com.ruoyi.oss.factory.OssFactory; |
| | | import com.ruoyi.oss.properties.CloudStorageProperties; |
| | | import com.ruoyi.oss.properties.CloudStorageProperties.MinioProperties; |
| | | import com.ruoyi.oss.service.abstractd.AbstractCloudStorageService; |
| | | import io.minio.MinioClient; |
| | | import io.minio.*; |
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.InputStream; |
| | | |
| | | /** |
| | |
| | | .endpoint(this.properties.getEndpoint()) |
| | | .credentials(this.properties.getAccessKey(), this.properties.getSecretKey()) |
| | | .build(); |
| | | String bucketName = this.properties.getBucketName(); |
| | | boolean exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()); |
| | | // ä¸åå¨å°±å建桶 |
| | | if (!exists) { |
| | | minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); |
| | | minioClient.setBucketPolicy(SetBucketPolicyArgs.builder() |
| | | .bucket(bucketName) |
| | | .config(getPolicy(bucketName, PolicyType.READ)) |
| | | .build()); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new IllegalArgumentException("Minioåå¨é
ç½®é误! è¯·æ£æ¥ç³»ç»é
ç½®!"); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String upload(byte[] data, String path) { |
| | | try { |
| | | public UploadResult upload(byte[] data, String path) { |
| | | return upload(new ByteArrayInputStream(data), path); |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult upload(InputStream inputStream, String path) { |
| | | try { |
| | | minioClient.putObject(PutObjectArgs.builder() |
| | | .bucket(properties.getBucketName()) |
| | | .object(path) |
| | | .contentType("application/octet-stream") |
| | | .stream(inputStream, inputStream.available(), -1) |
| | | .build()); |
| | | } catch (Exception e) { |
| | | throw new OssException("ä¸ä¼ æä»¶å¤±è´¥ï¼è¯·æ ¸å¯¹Minioé
置信æ¯"); |
| | | } |
| | | return this.properties.getEndpoint() + "/" + path; |
| | | return new UploadResult().setUrl(getBaseUrl() + path).setFilename(path); |
| | | } |
| | | |
| | | @Override |
| | | public void delete(String path) { |
| | | path = path.replace(getBaseUrl(), ""); |
| | | try { |
| | | |
| | | minioClient.removeObject(RemoveObjectArgs.builder() |
| | | .bucket(properties.getBucketName()) |
| | | .object(path) |
| | | .build()); |
| | | } catch (Exception e) { |
| | | throw new OssException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String uploadSuffix(byte[] data, String suffix) { |
| | | return upload(data, getPath(this.properties.getPrefix(), suffix)); |
| | | public UploadResult uploadSuffix(byte[] data, String suffix) { |
| | | return upload(data, getPath("", suffix)); |
| | | } |
| | | |
| | | @Override |
| | | public String uploadSuffix(InputStream inputStream, String suffix) { |
| | | return upload(inputStream, getPath(this.properties.getPrefix(), suffix)); |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix) { |
| | | return upload(inputStream, getPath("", suffix)); |
| | | } |
| | | |
| | | @Override |
| | | public void afterPropertiesSet() throws Exception { |
| | | OssFactory.register(getServiceType(),this); |
| | | OssFactory.register(getServiceType(), this); |
| | | } |
| | | |
| | | private String getBaseUrl() { |
| | | return properties.getEndpoint() + "/" + properties.getBucketName() + "/"; |
| | | } |
| | | |
| | | private String getPolicy(String bucketName, PolicyType policyType) { |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append("{\n"); |
| | | builder.append(" \"Statement\": [\n"); |
| | | builder.append(" {\n"); |
| | | builder.append(" \"Action\": [\n"); |
| | | if (policyType == PolicyType.WRITE) { |
| | | builder.append(" \"s3:GetBucketLocation\",\n"); |
| | | builder.append(" \"s3:ListBucketMultipartUploads\"\n"); |
| | | } else if (policyType == PolicyType.READ_WRITE) { |
| | | builder.append(" \"s3:GetBucketLocation\",\n"); |
| | | builder.append(" \"s3:ListBucket\",\n"); |
| | | builder.append(" \"s3:ListBucketMultipartUploads\"\n"); |
| | | } else { |
| | | builder.append(" \"s3:GetBucketLocation\"\n"); |
| | | } |
| | | builder.append(" ],\n"); |
| | | builder.append(" \"Effect\": \"Allow\",\n"); |
| | | builder.append(" \"Principal\": \"*\",\n"); |
| | | builder.append(" \"Resource\": \"arn:aws:s3:::"); |
| | | builder.append(bucketName); |
| | | builder.append("\"\n"); |
| | | builder.append(" },\n"); |
| | | if (PolicyType.READ.equals(policyType)) { |
| | | builder.append(" {\n"); |
| | | builder.append(" \"Action\": [\n"); |
| | | builder.append(" \"s3:ListBucket\"\n"); |
| | | builder.append(" ],\n"); |
| | | builder.append(" \"Effect\": \"Deny\",\n"); |
| | | builder.append(" \"Principal\": \"*\",\n"); |
| | | builder.append(" \"Resource\": \"arn:aws:s3:::"); |
| | | builder.append(bucketName); |
| | | builder.append("\"\n"); |
| | | builder.append(" },\n"); |
| | | } |
| | | builder.append(" {\n"); |
| | | builder.append(" \"Action\": "); |
| | | switch (policyType) { |
| | | case WRITE: |
| | | builder.append("[\n"); |
| | | builder.append(" \"s3:AbortMultipartUpload\",\n"); |
| | | builder.append(" \"s3:DeleteObject\",\n"); |
| | | builder.append(" \"s3:ListMultipartUploadParts\",\n"); |
| | | builder.append(" \"s3:PutObject\"\n"); |
| | | builder.append(" ],\n"); |
| | | break; |
| | | case READ_WRITE: |
| | | builder.append("[\n"); |
| | | builder.append(" \"s3:AbortMultipartUpload\",\n"); |
| | | builder.append(" \"s3:DeleteObject\",\n"); |
| | | builder.append(" \"s3:GetObject\",\n"); |
| | | builder.append(" \"s3:ListMultipartUploadParts\",\n"); |
| | | builder.append(" \"s3:PutObject\"\n"); |
| | | builder.append(" ],\n"); |
| | | break; |
| | | default: |
| | | builder.append("\"s3:GetObject\",\n"); |
| | | break; |
| | | } |
| | | builder.append(" \"Effect\": \"Allow\",\n"); |
| | | builder.append(" \"Principal\": \"*\",\n"); |
| | | builder.append(" \"Resource\": \"arn:aws:s3:::"); |
| | | builder.append(bucketName); |
| | | builder.append("/*\"\n"); |
| | | builder.append(" }\n"); |
| | | builder.append(" ],\n"); |
| | | builder.append(" \"Version\": \"2012-10-17\"\n"); |
| | | builder.append("}\n"); |
| | | return builder.toString(); |
| | | } |
| | | } |
| | |
| | | import com.qcloud.cos.auth.BasicCOSCredentials; |
| | | import com.qcloud.cos.auth.COSCredentials; |
| | | import com.qcloud.cos.region.Region; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.enumd.CloudServiceEnumd; |
| | | import com.ruoyi.oss.factory.OssFactory; |
| | | import com.ruoyi.oss.properties.CloudStorageProperties; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String upload(byte[] data, String path) { |
| | | public UploadResult upload(byte[] data, String path) { |
| | | // è
¾è®¯äºå¿
éè¦ä»¥"/"å¼å¤´ |
| | | if (!path.startsWith("/")) { |
| | | path = "/" + path; |
| | |
| | | // if (Convert.toInt(jsonObject.get("code")) != 0) { |
| | | // throw new OssException("æä»¶ä¸ä¼ 失败ï¼" + Convert.toStr(jsonObject.get("message"))); |
| | | // } |
| | | return this.properties.getDomain() + path; |
| | | return new UploadResult().setUrl(properties.getDomain() + "/" + path).setFilename(path); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String uploadSuffix(byte[] data, String suffix) { |
| | | public UploadResult uploadSuffix(byte[] data, String suffix) { |
| | | return upload(data, getPath(this.properties.getPrefix(), suffix)); |
| | | } |
| | | |
| | | @Override |
| | | public String uploadSuffix(InputStream inputStream, String suffix) { |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix) { |
| | | return upload(inputStream, getPath(this.properties.getPrefix(), suffix)); |
| | | } |
| | | |
| | |
| | | import com.qiniu.storage.Region; |
| | | import com.qiniu.storage.UploadManager; |
| | | import com.qiniu.util.Auth; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.enumd.CloudServiceEnumd; |
| | | import com.ruoyi.oss.exception.OssException; |
| | | import com.ruoyi.oss.factory.OssFactory; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String upload(byte[] data, String path) { |
| | | public UploadResult upload(byte[] data, String path) { |
| | | try { |
| | | Response res = uploadManager.put(data, path, token); |
| | | if (!res.isOK()) { |
| | |
| | | } catch (Exception e) { |
| | | throw new OssException("ä¸ä¼ æä»¶å¤±è´¥ï¼è¯·æ ¸å¯¹ä¸çé
置信æ¯"); |
| | | } |
| | | return this.properties.getDomain() + "/" + path; |
| | | return new UploadResult().setUrl(properties.getDomain() + "/" + path).setFilename(path); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String uploadSuffix(byte[] data, String suffix) { |
| | | public UploadResult uploadSuffix(byte[] data, String suffix) { |
| | | return upload(data, getPath(this.properties.getPrefix(), suffix)); |
| | | } |
| | | |
| | | @Override |
| | | public String uploadSuffix(InputStream inputStream, String suffix) { |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix) { |
| | | return upload(inputStream, getPath(this.properties.getPrefix(), suffix)); |
| | | } |
| | | |
| | |
| | | @ApiModelProperty("æä»¶å") |
| | | private String fileName; |
| | | /** |
| | | * åå |
| | | */ |
| | | @ApiModelProperty("åå") |
| | | private String originalName; |
| | | /** |
| | | * æä»¶åç¼å |
| | | */ |
| | | @ApiModelProperty("æä»¶åç¼å") |
| | |
| | | /** |
| | | * äºåå¨ä¸»é® |
| | | */ |
| | | @TableId(value = "oss_id") |
| | | @TableId(value = "oss_id", type = IdType.AUTO) |
| | | private Long ossId; |
| | | |
| | | /** |
| | |
| | | private String fileName; |
| | | |
| | | /** |
| | | * åå |
| | | */ |
| | | private String originalName; |
| | | |
| | | /** |
| | | * æä»¶åç¼å |
| | | */ |
| | | private String fileSuffix; |
| | |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.factory.OssFactory; |
| | | import com.ruoyi.oss.service.ICloudStorageService; |
| | | import com.ruoyi.system.bo.SysOssQueryBo; |
| | |
| | | Map<String, Object> params = bo.getParams(); |
| | | LambdaQueryWrapper<SysOss> lqw = Wrappers.lambdaQuery(); |
| | | lqw.like(StrUtil.isNotBlank(bo.getFileName()), SysOss::getFileName, bo.getFileName()); |
| | | lqw.like(StrUtil.isNotBlank(bo.getOriginalName()), SysOss::getOriginalName, bo.getOriginalName()); |
| | | lqw.eq(StrUtil.isNotBlank(bo.getFileSuffix()), SysOss::getFileSuffix, bo.getFileSuffix()); |
| | | lqw.eq(StrUtil.isNotBlank(bo.getUrl()), SysOss::getUrl, bo.getUrl()); |
| | | lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null, |
| | | SysOss::getCreateTime ,params.get("beginCreateTime"), params.get("endCreateTime")); |
| | | SysOss::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime")); |
| | | lqw.eq(StrUtil.isNotBlank(bo.getCreateBy()), SysOss::getCreateBy, bo.getCreateBy()); |
| | | lqw.eq(StrUtil.isNotBlank(bo.getService()), SysOss::getService, bo.getService()); |
| | | return lqw; |
| | |
| | | public SysOss upload(MultipartFile file) { |
| | | String originalfileName = file.getOriginalFilename(); |
| | | String suffix = StrUtil.sub(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); |
| | | ICloudStorageService storage = OssFactory.instance(); |
| | | UploadResult uploadResult; |
| | | try { |
| | | ICloudStorageService storage = OssFactory.instance(); |
| | | String url = storage.uploadSuffix(file.getBytes(), suffix); |
| | | // ä¿åæä»¶ä¿¡æ¯ |
| | | SysOss oss = new SysOss() |
| | | .setUrl(url).setFileSuffix(suffix) |
| | | .setFileName(originalfileName) |
| | | .setService(storage.getServiceType()); |
| | | save(oss); |
| | | return oss; |
| | | uploadResult = storage.uploadSuffix(file.getBytes(), suffix); |
| | | } catch (IOException e) { |
| | | throw new CustomException("æä»¶è¯»åå¼å¸¸!!!", e); |
| | | } |
| | | // ä¿åæä»¶ä¿¡æ¯ |
| | | SysOss oss = new SysOss() |
| | | .setUrl(uploadResult.getUrl()) |
| | | .setFileSuffix(suffix) |
| | | .setFileName(uploadResult.getFilename()) |
| | | .setOriginalName(originalfileName) |
| | | .setService(storage.getServiceType()); |
| | | save(oss); |
| | | return oss; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
| | | if(isValid){ |
| | | if (isValid) { |
| | | // åä¸äºä¸å¡ä¸çæ ¡éª,夿æ¯å¦éè¦æ ¡éª |
| | | } |
| | | List<SysOss> list = listByIds(ids); |
| | |
| | | private String fileName; |
| | | |
| | | /** |
| | | * åå |
| | | */ |
| | | @ApiModelProperty("åå") |
| | | private String originalName; |
| | | |
| | | /** |
| | | * æä»¶åç¼å |
| | | */ |
| | | @ApiModelProperty("æä»¶åç¼å") |
| | |
| | | @keyup.enter.native="handleQuery" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="åå" prop="originalName"> |
| | | <el-input |
| | | v-model="queryParams.originalName" |
| | | placeholder="请è¾å
¥åå" |
| | | clearable |
| | | size="small" |
| | | @keyup.enter.native="handleQuery" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="æä»¶åç¼" prop="fileSuffix"> |
| | | <el-input |
| | | v-model="queryParams.fileSuffix" |
| | |
| | | <el-table-column type="selection" width="55" align="center" /> |
| | | <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="createTime" width="180"> |
| | |
| | | pageNum: 1, |
| | | pageSize: 10, |
| | | fileName: undefined, |
| | | originalName: undefined, |
| | | fileSuffix: undefined, |
| | | url: undefined, |
| | | createTime: undefined, |
| | |
| | | ossId: undefined, |
| | | file: undefined, |
| | | fileName: undefined, |
| | | originalName: undefined, |
| | | fileSuffix: undefined, |
| | | url: undefined, |
| | | createTime: undefined, |
| | |
| | | create table sys_oss ( |
| | | oss_id bigint(20) not null auto_increment comment 'äºåå¨ä¸»é®', |
| | | file_name varchar(64) not null default '' comment 'æä»¶å', |
| | | original_name varchar(64) not null default '' comment 'åå', |
| | | file_suffix varchar(10) not null default '' comment 'æä»¶åç¼å', |
| | | url varchar(200) not null comment 'URLå°å', |
| | | create_time datetime default null comment 'å建æ¶é´', |
| | | create_by varchar(64) not null default '' comment 'ä¸ä¼ 人', |
| | | create_by varchar(64) default '' comment 'ä¸ä¼ 人', |
| | | update_time datetime default null comment 'æ´æ°æ¶é´', |
| | | update_by varchar(64) not null default '' comment 'æ´æ°äºº', |
| | | update_by varchar(64) default '' comment 'æ´æ°äºº', |
| | | service varchar(10) not null default 'minio' comment 'æå¡å', |
| | | primary key (oss_id) |
| | | ) engine=innodb comment ='OSSäºåå¨è¡¨'; |