| | |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | <!--minio文件存储--> |
| | | <dependency> |
| | | <groupId>io.minio</groupId> |
| | | <artifactId>minio</artifactId> |
| | | <version>6.0.8</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.panzhihua.applets.config.MinioUtil; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.apache.commons.lang3.RandomUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | |
| | | private WxMaConfiguration wxMaConfiguration; |
| | | @Resource |
| | | private CommunityService communityService; |
| | | @Resource |
| | | private MinioUtil minioUtil; |
| | | |
| | | public static void main(String[] args) { |
| | | // int nextInt = RandomUtils.nextInt(99999, 1000000); |
| | |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "新上传照片接口") |
| | | @PostMapping(value = "/uploadimages", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | try { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + "." + extension; |
| | | String imageUrl = minioUtil.upload(file, name); |
| | | return R.ok(imageUrl); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "发送验证码") |
| | | @PostMapping(value = "smscode") |
| | | public R smscode(@RequestBody UserPhoneVO userPhoneVO) { |
New file |
| | |
| | | package com.panzhihua.applets.config; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | |
| | | /** |
| | | * program 攀枝花智慧社区项目 description minio存储信息配置 |
| | | * |
| | | * @author manailin Date 2021-08-19 15:30 |
| | | **/ |
| | | @Data |
| | | @ConfigurationProperties(prefix = "minio") |
| | | public class MinioConfig { |
| | | |
| | | private String host; |
| | | |
| | | private String accessKey; |
| | | |
| | | private String secretKey; |
| | | |
| | | private String url; |
| | | |
| | | private String bucket; |
| | | |
| | | private String aliasName; |
| | | |
| | | private String aliasPCName; |
| | | } |
New file |
| | |
| | | package com.panzhihua.applets.config; |
| | | |
| | | import io.minio.MinioClient; |
| | | import io.minio.ObjectStat; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * program 攀枝花智慧社区项目 description minio工具类 |
| | | * |
| | | * @author manailin Date 2021-08-19 15:30 |
| | | **/ |
| | | @Component |
| | | @EnableConfigurationProperties(MinioConfig.class) |
| | | public class MinioUtil { |
| | | |
| | | @Resource |
| | | private MinioConfig minioProperties; |
| | | |
| | | public static byte[] toByteArray(InputStream input) throws IOException { |
| | | ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[4096]; |
| | | int n = 0; |
| | | while (-1 != (n = input.read(buffer))) { |
| | | output.write(buffer, 0, n); |
| | | } |
| | | return output.toByteArray(); |
| | | } |
| | | |
| | | /** |
| | | * 文件上传 |
| | | * |
| | | * @param file |
| | | * 要上传的文件 |
| | | * @return |
| | | */ |
| | | public String upload(MultipartFile file, String name) { |
| | | if (null != file) { |
| | | try { |
| | | UUID uuid = UUID.randomUUID(); |
| | | StringBuilder s = new StringBuilder(); |
| | | s.append(uuid.toString().replace("-", "")).append("/"); |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | // bucket 不存在,创建 |
| | | if (!minioClient.bucketExists(minioProperties.getBucket())) { |
| | | minioClient.makeBucket(minioProperties.getBucket()); |
| | | } |
| | | // 得到文件流 |
| | | InputStream input = file.getInputStream(); |
| | | // 文件名 |
| | | // String fileName = uuid + "/images." + FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String fileName = s.append(name).toString(); |
| | | String contentType = file.getContentType(); |
| | | minioClient.putObject(minioProperties.getBucket(), fileName, input, contentType); |
| | | StringBuilder fileUrl = new StringBuilder(minioProperties.getUrl()); |
| | | String url = fileUrl.append(fileName).toString(); |
| | | return url; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 文件下载 |
| | | * |
| | | * @param response |
| | | * @param url |
| | | */ |
| | | public void download(HttpServletResponse response, String url) { |
| | | // 从链接中得到文件名 |
| | | String replace = url.replace(minioProperties.getBucket() + "/", "#"); |
| | | String fileName = replace.split("#")[1]; |
| | | InputStream inputStream; |
| | | try { |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | ObjectStat stat = minioClient.statObject(minioProperties.getBucket(), fileName); |
| | | inputStream = minioClient.getObject(minioProperties.getBucket(), fileName); |
| | | response.setContentType(stat.contentType()); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
| | | IOUtils.copy(inputStream, response.getOutputStream()); |
| | | inputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 文件下载 |
| | | * |
| | | * @param response |
| | | * @param url |
| | | */ |
| | | public byte[] getBytes(HttpServletResponse response, String url) { |
| | | // 从链接中得到文件名 |
| | | String replace = url.replace(minioProperties.getBucket() + "/", "#"); |
| | | String fileName = replace.split("#")[1]; |
| | | InputStream inputStream; |
| | | byte[] bytes = new byte[0]; |
| | | try { |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | inputStream = minioClient.getObject(minioProperties.getBucket(), fileName); |
| | | bytes = toByteArray(inputStream); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return bytes; |
| | | } |
| | | } |
| | |
| | | active: ${ENV:dev} |
| | | servlet: |
| | | multipart: |
| | | max-file-size: 10MB |
| | | max-request-size: 10MB |
| | | max-file-size: 200MB |
| | | max-request-size: 200MB |
| | | |
| | | server: |
| | | max-http-header-size: 10MB |
| | |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <!--minio文件存储--> |
| | | <dependency> |
| | | <groupId>io.minio</groupId> |
| | | <artifactId>minio</artifactId> |
| | | <version>6.0.8</version> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.panzhihua.applets_backstage.config.MinioUtil; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | |
| | | private int port; |
| | | @Value("${ftp.url}") |
| | | private String url; |
| | | |
| | | @Resource |
| | | private MinioUtil minioUtil; |
| | | |
| | | @ApiOperation("新增广告") |
| | | @PostMapping("advertisement") |
| | |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "新上传照片接口") |
| | | @PostMapping(value = "/uploadimages", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | try { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + "." + extension; |
| | | String imageUrl = minioUtil.upload(file, name); |
| | | return R.ok(imageUrl); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "删除广告") |
| | | @DeleteMapping("advertisement") |
| | | public R deleteAdvertisement(@RequestParam("id") Long id) { |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.panzhihua.applets_backstage.config.MinioUtil; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | |
| | | @Resource |
| | | private CommunityService communityService; |
| | | |
| | | @Resource |
| | | private MinioUtil minioUtil; |
| | | |
| | | @Value("${excel.convenientUrl}") |
| | | private String excelConvenientUrl = "http://panzhihua.nhys.cdnhxx.com/web/bianminfuwudaoru.xlsx"; |
| | |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "新上传照片接口") |
| | | @PostMapping(value = "/upload/files", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | try { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + "." + extension; |
| | | String imageUrl = minioUtil.upload(file, name); |
| | | return R.ok(imageUrl); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "excel导入便民服务") |
| | | @PostMapping(value = "/serve/import", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R downloadTemplate(@RequestParam MultipartFile file, HttpServletRequest request) { |
New file |
| | |
| | | package com.panzhihua.applets_backstage.config; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | |
| | | /** |
| | | * program 攀枝花智慧社区项目 description minio存储信息配置 |
| | | * |
| | | * @author manailin Date 2021-08-19 15:30 |
| | | **/ |
| | | @Data |
| | | @ConfigurationProperties(prefix = "minio") |
| | | public class MinioConfig { |
| | | |
| | | private String host; |
| | | |
| | | private String accessKey; |
| | | |
| | | private String secretKey; |
| | | |
| | | private String url; |
| | | |
| | | private String bucket; |
| | | |
| | | private String aliasName; |
| | | |
| | | private String aliasPCName; |
| | | } |
New file |
| | |
| | | package com.panzhihua.applets_backstage.config; |
| | | |
| | | import io.minio.MinioClient; |
| | | import io.minio.ObjectStat; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * program 攀枝花智慧社区项目 description minio工具类 |
| | | * |
| | | * @author manailin Date 2021-08-19 15:30 |
| | | **/ |
| | | @Component |
| | | @EnableConfigurationProperties(MinioConfig.class) |
| | | public class MinioUtil { |
| | | |
| | | @Resource |
| | | private MinioConfig minioProperties; |
| | | |
| | | public static byte[] toByteArray(InputStream input) throws IOException { |
| | | ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[4096]; |
| | | int n = 0; |
| | | while (-1 != (n = input.read(buffer))) { |
| | | output.write(buffer, 0, n); |
| | | } |
| | | return output.toByteArray(); |
| | | } |
| | | |
| | | /** |
| | | * 文件上传 |
| | | * |
| | | * @param file |
| | | * 要上传的文件 |
| | | * @return |
| | | */ |
| | | public String upload(MultipartFile file, String name) { |
| | | if (null != file) { |
| | | try { |
| | | UUID uuid = UUID.randomUUID(); |
| | | StringBuilder s = new StringBuilder(); |
| | | s.append(uuid.toString().replace("-", "")).append("/"); |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | // bucket 不存在,创建 |
| | | if (!minioClient.bucketExists(minioProperties.getBucket())) { |
| | | minioClient.makeBucket(minioProperties.getBucket()); |
| | | } |
| | | // 得到文件流 |
| | | InputStream input = file.getInputStream(); |
| | | // 文件名 |
| | | // String fileName = uuid + "/images." + FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String fileName = s.append(name).toString(); |
| | | String contentType = file.getContentType(); |
| | | minioClient.putObject(minioProperties.getBucket(), fileName, input, contentType); |
| | | StringBuilder fileUrl = new StringBuilder(minioProperties.getUrl()); |
| | | String url = fileUrl.append(fileName).toString(); |
| | | return url; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 文件下载 |
| | | * |
| | | * @param response |
| | | * @param url |
| | | */ |
| | | public void download(HttpServletResponse response, String url) { |
| | | // 从链接中得到文件名 |
| | | String replace = url.replace(minioProperties.getBucket() + "/", "#"); |
| | | String fileName = replace.split("#")[1]; |
| | | InputStream inputStream; |
| | | try { |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | ObjectStat stat = minioClient.statObject(minioProperties.getBucket(), fileName); |
| | | inputStream = minioClient.getObject(minioProperties.getBucket(), fileName); |
| | | response.setContentType(stat.contentType()); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
| | | IOUtils.copy(inputStream, response.getOutputStream()); |
| | | inputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 文件下载 |
| | | * |
| | | * @param response |
| | | * @param url |
| | | */ |
| | | public byte[] getBytes(HttpServletResponse response, String url) { |
| | | // 从链接中得到文件名 |
| | | String replace = url.replace(minioProperties.getBucket() + "/", "#"); |
| | | String fileName = replace.split("#")[1]; |
| | | InputStream inputStream; |
| | | byte[] bytes = new byte[0]; |
| | | try { |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | inputStream = minioClient.getObject(minioProperties.getBucket(), fileName); |
| | | bytes = toByteArray(inputStream); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return bytes; |
| | | } |
| | | } |
| | |
| | | active: ${ENV:dev} |
| | | servlet: |
| | | multipart: |
| | | max-file-size: 10MB |
| | | max-request-size: 10MB |
| | | max-file-size: 200MB |
| | | max-request-size: 200MB |
| | | |
| | | eureka: |
| | | client: |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | |
| | | private Integer isBoutique; |
| | | |
| | | @ApiModelProperty("发布时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date createAt; |
| | | |
| | | @ApiModelProperty("最后回复时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date replyAt; |
| | | |
| | | @ApiModelProperty("邻里圈评论列表") |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.panzhihua.community_backstage.config.MinioUtil; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | |
| | | private int port; |
| | | @Value("${ftp.url}") |
| | | private String url; |
| | | |
| | | @Resource |
| | | private MinioUtil minioUtil; |
| | | |
| | | @ApiOperation(value = "社区所有启用的党组织列表", response = PartyOrganizationVO.class) |
| | | @GetMapping("listpartyorganization") |
| | |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "新上传照片接口") |
| | | @PostMapping(value = "/uploadimages", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | try { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + "." + extension; |
| | | String imageUrl = minioUtil.upload(file, name); |
| | | return R.ok(imageUrl); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "批量新增党员导入excel") |
| | | @PostMapping(value = "downloadtemplate", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R downloadTemplate(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | |
| | | active: ${ENV:dev} |
| | | servlet: |
| | | multipart: |
| | | max-file-size: 100MB |
| | | max-request-size: 100MB |
| | | max-file-size: 200MB |
| | | max-request-size: 200MB |
| | | |
| | | eureka: |
| | | client: |
| | |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <!--minio文件存储--> |
| | | <dependency> |
| | | <groupId>io.minio</groupId> |
| | | <artifactId>minio</artifactId> |
| | | <version>6.0.8</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.panzhihua.grid_app.config.MinioUtil; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | private String url; |
| | | @Resource |
| | | private CommunityService communityService; |
| | | @Resource |
| | | private MinioUtil minioUtil; |
| | | |
| | | @ApiOperation(value = "上传照片/视频 (jpg/jpeg/png/mp4/mov)") |
| | | @PostMapping(value = "uploadimage", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "新上传照片接口") |
| | | @PostMapping(value = "/uploadimages", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | try { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + "." + extension; |
| | | String imageUrl = minioUtil.upload(file, name); |
| | | return R.ok(imageUrl); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "批量上传照片/视频 (jpg/jpeg/png/mp4/mov)") |
| | | @PostMapping(value = "uploads", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile[] files, HttpServletRequest request) throws IOException { |
| | | public R uploads(@RequestParam MultipartFile[] files, HttpServletRequest request) throws IOException { |
| | | // 微信图片内容校验 |
| | | // WxMaSecCheckService wxMaSecCheckService = wxMaConfiguration.getMaService().getSecCheckService(); |
| | | String property = System.getProperty("user.dir"); |
| | |
| | | return R.ok(urlList); |
| | | } |
| | | |
| | | @ApiOperation(value = "新批量文件上传接口") |
| | | @PostMapping(value = "/uploadimages", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R ossUploads(@RequestParam MultipartFile[] files, HttpServletRequest request) { |
| | | try { |
| | | List<String> urlList = new ArrayList<>(); |
| | | for (MultipartFile file : files) { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + "." + extension; |
| | | String imageUrl = minioUtil.upload(file, name); |
| | | urlList.add(imageUrl); |
| | | } |
| | | return R.ok(urlList); |
| | | } catch (Exception e) { |
| | | log.error("上传文件失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/getConf/noToken") |
| | | @ApiOperation(value = "根据code查询系统配置") |
| | | public R getConf(@RequestParam("code") String code) { |
New file |
| | |
| | | package com.panzhihua.grid_app.config; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | |
| | | /** |
| | | * program 攀枝花智慧社区项目 description minio存储信息配置 |
| | | * |
| | | * @author manailin Date 2021-08-19 15:30 |
| | | **/ |
| | | @Data |
| | | @ConfigurationProperties(prefix = "minio") |
| | | public class MinioConfig { |
| | | |
| | | private String host; |
| | | |
| | | private String accessKey; |
| | | |
| | | private String secretKey; |
| | | |
| | | private String url; |
| | | |
| | | private String bucket; |
| | | |
| | | private String aliasName; |
| | | |
| | | private String aliasPCName; |
| | | } |
New file |
| | |
| | | package com.panzhihua.grid_app.config; |
| | | |
| | | import io.minio.MinioClient; |
| | | import io.minio.ObjectStat; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * program 攀枝花智慧社区项目 description minio工具类 |
| | | * |
| | | * @author manailin Date 2021-08-19 15:30 |
| | | **/ |
| | | @Component |
| | | @EnableConfigurationProperties(MinioConfig.class) |
| | | public class MinioUtil { |
| | | |
| | | @Resource |
| | | private MinioConfig minioProperties; |
| | | |
| | | public static byte[] toByteArray(InputStream input) throws IOException { |
| | | ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[4096]; |
| | | int n = 0; |
| | | while (-1 != (n = input.read(buffer))) { |
| | | output.write(buffer, 0, n); |
| | | } |
| | | return output.toByteArray(); |
| | | } |
| | | |
| | | /** |
| | | * 文件上传 |
| | | * |
| | | * @param file |
| | | * 要上传的文件 |
| | | * @return |
| | | */ |
| | | public String upload(MultipartFile file, String name) { |
| | | if (null != file) { |
| | | try { |
| | | UUID uuid = UUID.randomUUID(); |
| | | StringBuilder s = new StringBuilder(); |
| | | s.append(uuid.toString().replace("-", "")).append("/"); |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | // bucket 不存在,创建 |
| | | if (!minioClient.bucketExists(minioProperties.getBucket())) { |
| | | minioClient.makeBucket(minioProperties.getBucket()); |
| | | } |
| | | // 得到文件流 |
| | | InputStream input = file.getInputStream(); |
| | | // 文件名 |
| | | // String fileName = uuid + "/images." + FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String fileName = s.append(name).toString(); |
| | | String contentType = file.getContentType(); |
| | | minioClient.putObject(minioProperties.getBucket(), fileName, input, contentType); |
| | | StringBuilder fileUrl = new StringBuilder(minioProperties.getUrl()); |
| | | String url = fileUrl.append(fileName).toString(); |
| | | return url; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 文件下载 |
| | | * |
| | | * @param response |
| | | * @param url |
| | | */ |
| | | public void download(HttpServletResponse response, String url) { |
| | | // 从链接中得到文件名 |
| | | String replace = url.replace(minioProperties.getBucket() + "/", "#"); |
| | | String fileName = replace.split("#")[1]; |
| | | InputStream inputStream; |
| | | try { |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | ObjectStat stat = minioClient.statObject(minioProperties.getBucket(), fileName); |
| | | inputStream = minioClient.getObject(minioProperties.getBucket(), fileName); |
| | | response.setContentType(stat.contentType()); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
| | | IOUtils.copy(inputStream, response.getOutputStream()); |
| | | inputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 文件下载 |
| | | * |
| | | * @param response |
| | | * @param url |
| | | */ |
| | | public byte[] getBytes(HttpServletResponse response, String url) { |
| | | // 从链接中得到文件名 |
| | | String replace = url.replace(minioProperties.getBucket() + "/", "#"); |
| | | String fileName = replace.split("#")[1]; |
| | | InputStream inputStream; |
| | | byte[] bytes = new byte[0]; |
| | | try { |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | inputStream = minioClient.getObject(minioProperties.getBucket(), fileName); |
| | | bytes = toByteArray(inputStream); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return bytes; |
| | | } |
| | | } |
| | |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <!--minio文件存储--> |
| | | <dependency> |
| | | <groupId>io.minio</groupId> |
| | | <artifactId>minio</artifactId> |
| | | <version>6.0.8</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import java.util.UUID; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.panzhihua.grid_backstage.config.MinioUtil; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | private int port; |
| | | @Value("${ftp.url}") |
| | | private String url; |
| | | @Resource |
| | | private MinioUtil minioUtil; |
| | | |
| | | @ApiOperation(value = "上传照片/视频 (jpg/jpeg/png/mp4/mov)") |
| | | @PostMapping(value = "uploadimage", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "新上传照片接口") |
| | | @PostMapping(value = "/uploadimages", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | try { |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + "." + extension; |
| | | String imageUrl = minioUtil.upload(file, name); |
| | | return R.ok(imageUrl); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.panzhihua.grid_backstage.config; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | |
| | | /** |
| | | * program 攀枝花智慧社区项目 description minio存储信息配置 |
| | | * |
| | | * @author manailin Date 2021-08-19 15:30 |
| | | **/ |
| | | @Data |
| | | @ConfigurationProperties(prefix = "minio") |
| | | public class MinioConfig { |
| | | |
| | | private String host; |
| | | |
| | | private String accessKey; |
| | | |
| | | private String secretKey; |
| | | |
| | | private String url; |
| | | |
| | | private String bucket; |
| | | |
| | | private String aliasName; |
| | | |
| | | private String aliasPCName; |
| | | } |
New file |
| | |
| | | package com.panzhihua.grid_backstage.config; |
| | | |
| | | import io.minio.MinioClient; |
| | | import io.minio.ObjectStat; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * program 攀枝花智慧社区项目 description minio工具类 |
| | | * |
| | | * @author manailin Date 2021-08-19 15:30 |
| | | **/ |
| | | @Component |
| | | @EnableConfigurationProperties(MinioConfig.class) |
| | | public class MinioUtil { |
| | | |
| | | @Resource |
| | | private MinioConfig minioProperties; |
| | | |
| | | public static byte[] toByteArray(InputStream input) throws IOException { |
| | | ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[4096]; |
| | | int n = 0; |
| | | while (-1 != (n = input.read(buffer))) { |
| | | output.write(buffer, 0, n); |
| | | } |
| | | return output.toByteArray(); |
| | | } |
| | | |
| | | /** |
| | | * 文件上传 |
| | | * |
| | | * @param file |
| | | * 要上传的文件 |
| | | * @return |
| | | */ |
| | | public String upload(MultipartFile file, String name) { |
| | | if (null != file) { |
| | | try { |
| | | UUID uuid = UUID.randomUUID(); |
| | | StringBuilder s = new StringBuilder(); |
| | | s.append(uuid.toString().replace("-", "")).append("/"); |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | // bucket 不存在,创建 |
| | | if (!minioClient.bucketExists(minioProperties.getBucket())) { |
| | | minioClient.makeBucket(minioProperties.getBucket()); |
| | | } |
| | | // 得到文件流 |
| | | InputStream input = file.getInputStream(); |
| | | // 文件名 |
| | | // String fileName = uuid + "/images." + FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String fileName = s.append(name).toString(); |
| | | String contentType = file.getContentType(); |
| | | minioClient.putObject(minioProperties.getBucket(), fileName, input, contentType); |
| | | StringBuilder fileUrl = new StringBuilder(minioProperties.getUrl()); |
| | | String url = fileUrl.append(fileName).toString(); |
| | | return url; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 文件下载 |
| | | * |
| | | * @param response |
| | | * @param url |
| | | */ |
| | | public void download(HttpServletResponse response, String url) { |
| | | // 从链接中得到文件名 |
| | | String replace = url.replace(minioProperties.getBucket() + "/", "#"); |
| | | String fileName = replace.split("#")[1]; |
| | | InputStream inputStream; |
| | | try { |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | ObjectStat stat = minioClient.statObject(minioProperties.getBucket(), fileName); |
| | | inputStream = minioClient.getObject(minioProperties.getBucket(), fileName); |
| | | response.setContentType(stat.contentType()); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
| | | IOUtils.copy(inputStream, response.getOutputStream()); |
| | | inputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 文件下载 |
| | | * |
| | | * @param response |
| | | * @param url |
| | | */ |
| | | public byte[] getBytes(HttpServletResponse response, String url) { |
| | | // 从链接中得到文件名 |
| | | String replace = url.replace(minioProperties.getBucket() + "/", "#"); |
| | | String fileName = replace.split("#")[1]; |
| | | InputStream inputStream; |
| | | byte[] bytes = new byte[0]; |
| | | try { |
| | | MinioClient minioClient = new MinioClient(minioProperties.getHost(), minioProperties.getAccessKey(), |
| | | minioProperties.getSecretKey()); |
| | | inputStream = minioClient.getObject(minioProperties.getBucket(), fileName); |
| | | bytes = toByteArray(inputStream); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return bytes; |
| | | } |
| | | } |
| | |
| | | active: ${ENV:dev} |
| | | servlet: |
| | | multipart: |
| | | max-file-size: 10MB |
| | | max-request-size: 10MB |
| | | max-file-size: 200MB |
| | | max-request-size: 200MB |
| | | |
| | | eureka: |
| | | client: |
| | |
| | | noLoginUrl.add("/api/applets/community/pagedynamic"); |
| | | noLoginUrl.add("/api/applets/community/pageactivity"); |
| | | noLoginUrl.add("/api/applets/community/listactivitysign"); |
| | | noLoginUrl.add("/api/applets/common/uploadimages"); |
| | | noLoginUrl.add("/api/applets/workguide/pageworkguide"); |
| | | noLoginUrl.add("/api/applets/workguide/detailworkguide"); |
| | | noLoginUrl.add("/api/applets/workguide/list"); |
| | |
| | | noLoginUrl.add("/api/applets/community/pagevolunteer"); |
| | | noLoginUrl.add("/api/applets/community/volunteer"); |
| | | noLoginUrl.add("/api/applets/community/evaluate/page"); |
| | | |
| | | if (noLoginUrl.contains(requestURI)) { |
| | | List<SimpleGrantedAuthority> authorities = new ArrayList<>(); |
| | | authorities.add(new SimpleGrantedAuthority(SecurityConstants.ROLE_APPLETS)); |