java文件客户端下载_使用Java写一个minio的客户端上传下载文件
标签:color ati tty java system wired format media param
前言:
确保已经安装了minio的服务端
代码:
pom.xml
dependency>
groupId>io.miniogroupId>
artifactId>minioartifactId>
version>7.0.2version>
dependency>
application.yml
server:
port:90
minio:
url: http://10.69.94.140:9000
accessKey: 账号
secretKey: 密码
defaultFolder:/
MinioProperties.java
@ConfigurationProperties("minio")
@Datapublic classMinioProperties {privateString url;privateString accessKey;privateString secretKey;privateString defaultFolder;
}
SpringConfig.java
@Configuration
@EnableConfigurationProperties(MinioProperties.class)
@Slf4jpublic classSpringConfig {
@AutowiredprivateMinioProperties minioProperties;
@BeanpublicMinioClient minioClient() {try{return newMinioClient(minioProperties.getUrl(), minioProperties.getAccessKey(), minioProperties.getSecretKey());
}catch(Exception e) {
log.error(e.toString());
}return null;
}
}
ImagesController.java
@RestController
@RequestMapping("/image")
@Slf4j
@CrossOrigin(origins= "*")public classImageController {
@AutowiredprivateFileService fileService;/*******
* Get image file, this method return an image type file which can be displayed in browser.
* @param bucketName, system, each system should belong a special bucket.
* @param category, a system may contain multiple category
* @param fileName*/@GetMapping(value= "/get/{bucketName}/{category}/{objectName}/{fileName}", produces =MediaType.IMAGE_JPEG_VALUE)public byte[] get(@PathVariable("bucketName") String bucketName, @PathVariable("category") String category,
@PathVariable("objectName") String objectName,
@PathVariable("fileName") String fileName) throws Exception {returnfileService.getFile(bucketName, category, objectName);
}
@GetMapping("/download/{bucketName}/{category}/{objectName}/{fileName}")public void download(@PathVariable("bucketName") String bucketName, @PathVariable("category") String category,
@PathVariable("objectName") String objectName,
@PathVariable("fileName") String fileName, HttpServletResponse response) throws Exception {byte[] buffer =fileService.getFile(bucketName, category, objectName);
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
response.getOutputStream().write(buffer);
response.flushBuffer();
response.getOutputStream().close();
}
@PostMapping("/upload/{bucketName}/{category}")public String upload(@PathVariable("bucketName") String bucketName, @PathVariable("category") String category,
@RequestParam("file") MultipartFile file) throws Exception {
String objectName=UUID.randomUUID().toString();
fileService.storeFile(bucketName, category, objectName, file.getBytes());return String.format("image/get/%s/%s/%s/%s", bucketName, category, objectName, file.getOriginalFilename());
}
}
FilesController.java
@RestController
@RequestMapping("/files")
@Slf4j
@CrossOrigin(origins= "*")public classFilesController {
@AutowiredprivateFileService fileService;
@GetMapping("/download/{bucketName}/{category}/{objectName}/{fileName}")public void download(@PathVariable("bucketName") String bucketName, @PathVariable("category") String category,
@PathVariable("objectName") String objectName, @PathVariable("fileName") String fileName, HttpServletResponse response) throws Exception {byte[] buffer =fileService.getFile(bucketName, category, objectName);
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
response.getOutputStream().write(buffer);
response.flushBuffer();
response.getOutputStream().close();
}
@PostMapping("/upload/{bucketName}/{category}")public String upload(@PathVariable("bucketName") String bucketName, @PathVariable("category") String category,
@RequestParam("file") MultipartFile file) throws Exception {
String objectName=UUID.randomUUID().toString();
fileService.storeFile(bucketName, category, objectName, file.getBytes());return String.format("files/download/%s/%s/%s/%s", bucketName, category, objectName, file.getOriginalFilename());
}
}
upload.html
DOCTYPE html>
htmllang="en">
head>
metacharset="UTF-8">
title>Upload file testtitle>
head>
body>
formaction="http://localhost:90/image/upload/zeng/test"method="post"enctype="multipart/form-data">
inputtype="file"name="file" />
inputtype="submit"value="Submit">
form>
body>
html>
使用Java写一个minio的客户端上传下载文件
标签:color ati tty java system wired format media param
java文件客户端下载_使用Java写一个minio的客户端上传下载文件相关推荐
- aws php 上传文件 限制大小_如何压缩PDF文件大小,满足各种上传大小要求
介绍 今天我们来说一个小技巧,就是对PDF文件大小的压缩.那么这个问题是怎么来的呢,我们在系统上传PDF文件的时候,由于系统限制,PDF大小受到了限制,我们需要对PDF进行压缩小一点进行上传,才能满足 ...
- python自动上传图片_使用Python实现一个简单的图片上传存储服务
使用flask实现的一个简单的图片上传服务 设计初衷 对于图片的存储,有很多选择,一般采用云服务如(七牛,又拍等),但是国内的服务像七牛 自定义域名竟然需要域名备案(Excuse me,当初就是因为备 ...
- java设计中期检查表_毕业实习中期检查表以附件形式上传
[简答题]The Most Impressive Movie [单选题]设有以下语句: char x=3,y=6,z; z=x^y<<2; 则 z 的十六进制数值是( ). (1.5分) ...
- 服务器如何下载百度网盘文件?Linux服务器如何在百度网盘中连接、上传下载;在Linux服务器上下载百度云盘中的资料
前言 百度云提供Python包bypy进行远程服务器的对接然后下载: https://github.com/houtianze/bypy 可以通过pip直接下载,授权本人的百度云账号后,就可以直接使L ...
- php复制mysql文件路径_与php 有关的问题 如何将上传的文件路径 保存到数据库中...
就是不知道为什么插入不进去求指点最好是给改改谢谢新手见笑了<?phpinclude ("lianjie.php");if(is_uploaded_file($_FILES[' ...
- python编的俄罗斯方块游戏下载_用python写一个俄罗斯方块小游戏
相信大家都玩过俄罗斯方块吧,应该是小时候的回忆吧,但是想不想了解一下这个程序是怎么写出来的呢,自己写出来的应该玩起来更有感觉吧! 感觉还是蛮好玩吧! 接下来,我就分享一下这个游戏的源码过程啊! 先用p ...
- python post上传大文件分片上传_基于七牛 用python实现分片上传 创建文件报错701...
创建文件时出错: 701 Unknown {"error":"block 0: yonginvalid context"} 抓包结果: POST /mkfile ...
- Java Web 文件上传下载
文章目录 1文件上传概述 1.1文件上传的作用 1.2文件上传对页面的要求 1.3 比对文件上传表单和普通文本表单的区别 1.4 对普通文本表单的测试 1.5 文件上传对Servlet的要求 2 co ...
- java上传下载_Java文件上传与文件下载实现方法详解
本文实例讲述了Java文件上传与文件下载实现方法.分享给大家供大家参考,具体如下: Java文件上传 数据上传是客户端向服务器端上传数据,客户端向服务器发送的所有请求都属于数据上传.文件上传是数据上传 ...
最新文章
- 常见数字IC设计、FPGA工程师面试题
- 判断机器学习算法或深度学习算法优势常考虑的点
- 微信小程序(5)wx:if 条件判断
- 以太网RJ45 接线标准 线序(备忘)
- php设计是什么意思,php – 什么是更好的设计?
- kafka调试工具kafkacat的使用
- sleep、wait、yield、join区别
- Python 绘图,我只用 Matplotlib
- python threadPool 与 multiprocessing.Pool
- Mydumper 多线程备份工具
- Java实现网上书店管理系统(idea+MySQL+navicat)
- python新浪股票接口_新浪股票数据接口
- 震网三代在metasploit-framework上的复现与利用
- 计算机网络体系结构各层中的网络设备
- 重磅!罗振宇跨年演讲:扎心5问
- 三星发布家用microLED电视,LG感到压力很大
- bibtex 共生_游戏与音乐的共生
- YY游戏云平台在AngularJS上的实践总结
- 百度map的简单例子
- 用 Python 运行神经网络
热门文章
- Spring的Java配置
- 左神算法:调整搜索二叉树中两个错误的节点(Java版)
- 【Servlet】Tomcat公共 / 项目独立的 web.xml / server.xml 文件讲解
- 【Modelsim零基础入门】verilog仿真程序:1-bit A+B
- 响应式关系数据库处理R2DBC
- 理解MySQL——架构与概念
- 我的博客即将同步至腾讯云+社区
- MySql 中 case when then else end 的用法
- Gradle与project(三)
- 【简便解法】1083 是否存在相等的差 (20分)_14行代码AC