update OSS接口增加通用contentType
| | |
| | | <parent> |
| | | <artifactId>ruoyi-vue-plus</artifactId> |
| | | <groupId>com.ruoyi</groupId> |
| | | <version>2.5.1</version> |
| | | <version>2.5.2</version> |
| | | </parent> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | |
| | |
| | | */ |
| | | public final static String CLOUD_STORAGE_CONFIG_KEY = "sys.oss.cloudStorageService"; |
| | | |
| | | public final static String DEFAULT_CONTENT_TYPE = "application/octet-stream"; |
| | | |
| | | |
| | | } |
| | |
| | | * @param path 文件路径,包含文件名 |
| | | * @return 返回http地址 |
| | | */ |
| | | UploadResult upload(byte[] data, String path); |
| | | UploadResult upload(byte[] data, String path, String contentType); |
| | | |
| | | /** |
| | | * 文件删除 |
| | |
| | | * @param suffix 后缀 |
| | | * @return 返回http地址 |
| | | */ |
| | | UploadResult uploadSuffix(byte[] data, String suffix); |
| | | UploadResult uploadSuffix(byte[] data, String suffix, String contentType); |
| | | |
| | | /** |
| | | * 文件上传 |
| | |
| | | * @param path 文件路径,包含文件名 |
| | | * @return 返回http地址 |
| | | */ |
| | | UploadResult upload(InputStream inputStream, String path); |
| | | UploadResult upload(InputStream inputStream, String path, String contentType); |
| | | |
| | | /** |
| | | * 文件上传 |
| | |
| | | * @param suffix 后缀 |
| | | * @return 返回http地址 |
| | | */ |
| | | UploadResult uploadSuffix(InputStream inputStream, String suffix); |
| | | UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public abstract UploadResult upload(byte[] data, String path); |
| | | public abstract UploadResult upload(byte[] data, String path, String contentType); |
| | | |
| | | @Override |
| | | public abstract void delete(String path); |
| | | |
| | | @Override |
| | | public UploadResult upload(InputStream inputStream, String path) { |
| | | public UploadResult upload(InputStream inputStream, String path, String contentType) { |
| | | byte[] data = IoUtil.readBytes(inputStream); |
| | | return this.upload(data, path); |
| | | return this.upload(data, path, contentType); |
| | | } |
| | | |
| | | @Override |
| | | public abstract UploadResult uploadSuffix(byte[] data, String suffix); |
| | | public abstract UploadResult uploadSuffix(byte[] data, String suffix, String contentType); |
| | | |
| | | @Override |
| | | public abstract UploadResult uploadSuffix(InputStream inputStream, String suffix); |
| | | public abstract UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType); |
| | | |
| | | @Override |
| | | public abstract void afterPropertiesSet() throws Exception; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult upload(byte[] data, String path) { |
| | | return upload(new ByteArrayInputStream(data), path); |
| | | public UploadResult upload(byte[] data, String path, String contentType) { |
| | | return upload(new ByteArrayInputStream(data), path, contentType); |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult upload(InputStream inputStream, String path) { |
| | | public UploadResult upload(InputStream inputStream, String path, String contentType) { |
| | | try { |
| | | client.putObject(this.properties.getBucketName(), path, inputStream); |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult uploadSuffix(byte[] data, String suffix) { |
| | | return upload(data, getPath(this.properties.getPrefix(), suffix)); |
| | | public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) { |
| | | return upload(data, getPath(this.properties.getPrefix(), suffix), contentType); |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix) { |
| | | return upload(inputStream, getPath(this.properties.getPrefix(), suffix)); |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) { |
| | | return upload(inputStream, getPath(this.properties.getPrefix(), suffix), contentType); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult upload(byte[] data, String path) { |
| | | return upload(new ByteArrayInputStream(data), path); |
| | | public UploadResult upload(byte[] data, String path, String contentType) { |
| | | return upload(new ByteArrayInputStream(data), path, contentType); |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult upload(InputStream inputStream, String path) { |
| | | public UploadResult upload(InputStream inputStream, String path, String contentType) { |
| | | try { |
| | | minioClient.putObject(PutObjectArgs.builder() |
| | | .bucket(properties.getBucketName()) |
| | | .object(path) |
| | | .contentType("application/octet-stream") |
| | | .contentType(StrUtil.blankToDefault(contentType, CloudConstant.DEFAULT_CONTENT_TYPE)) |
| | | .stream(inputStream, inputStream.available(), -1) |
| | | .build()); |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult uploadSuffix(byte[] data, String suffix) { |
| | | return upload(data, getPath("", suffix)); |
| | | public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) { |
| | | return upload(data, getPath("", suffix), contentType); |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix) { |
| | | return upload(inputStream, getPath("", suffix)); |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) { |
| | | return upload(inputStream, getPath("", suffix), contentType); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult upload(byte[] data, String path) { |
| | | public UploadResult upload(byte[] data, String path, String contentType) { |
| | | // 腾讯云必需要以"/"开头 |
| | | if (!path.startsWith("/")) { |
| | | path = "/" + path; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult uploadSuffix(byte[] data, String suffix) { |
| | | return upload(data, getPath(this.properties.getPrefix(), suffix)); |
| | | public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) { |
| | | return upload(data, getPath(this.properties.getPrefix(), suffix), contentType); |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix) { |
| | | return upload(inputStream, getPath(this.properties.getPrefix(), suffix)); |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) { |
| | | return upload(inputStream, getPath(this.properties.getPrefix(), suffix), contentType); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult upload(byte[] data, String path) { |
| | | public UploadResult upload(byte[] data, String path, String contentType) { |
| | | try { |
| | | Response res = uploadManager.put(data, path, token); |
| | | if (!res.isOK()) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult uploadSuffix(byte[] data, String suffix) { |
| | | return upload(data, getPath(this.properties.getPrefix(), suffix)); |
| | | public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) { |
| | | return upload(data, getPath(this.properties.getPrefix(), suffix), contentType); |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix) { |
| | | return upload(inputStream, getPath(this.properties.getPrefix(), suffix)); |
| | | public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) { |
| | | return upload(inputStream, getPath(this.properties.getPrefix(), suffix), contentType); |
| | | } |
| | | |
| | | @Override |
| | |
| | | ICloudStorageService storage = OssFactory.instance(); |
| | | UploadResult uploadResult; |
| | | try { |
| | | uploadResult = storage.uploadSuffix(file.getBytes(), suffix); |
| | | uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType()); |
| | | } catch (IOException e) { |
| | | throw new CustomException("文件读取异常!!!", e); |
| | | } |