81,092
社区成员
发帖
与我相关
我的任务
分享
@GetMapping(value = "/test1")
// @ResponseBody
public void test1(HttpServletResponse response) throws XmlPullParserException, NoSuchAlgorithmException, InvalidKeyException, IOException {
try {
// //本地
// MinioClient minioClient = new MinioClient("http://localhost:9000", "Z3TFF3HKCMFZP5BRN62T",
// "GOIuA5leqkPEZDTi2+t2dpM3kc7XiYUoNWb+0E9r");
//服务器
MinioClient minioClient = new MinioClient("http://localhost:9000", "Z3TFF3HKCMFZP5BRN62T",
"GOIuA5leqkPEZDTi2+t2dpM3kc7XiYUoNWb+0E9r");
// Check whether the object exists using statObject().
// If the object is not found, statObject() throws an exception,
// else it means that the object exists.
// Execution is successful.
minioClient.statObject("asiatrip", "asiaphotos.zip");
// Get input stream to have content of 'my-objectname' from 'my-bucketname'
// 配置文件下载
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
// 下载文件能正常显示中文
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("asiaphotos.zip", "UTF-8"));
OutputStream outputStream = response.getOutputStream();
InputStream stream = minioClient.getObject("asiatrip", "asiaphotos.zip");
// Read the input stream and print to the console till EOF.
byte[] buf = new byte[16384];
int bytesRead;
while ((bytesRead = stream.read(buf, 0, buf.length)) >= 0) {
System.out.println(new String(buf, 0, bytesRead));
outputStream.write(buf, 0, bytesRead);
}
response.flushBuffer();
// Close the input stream.
stream.close();
outputStream.close();
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
}
}
//通过文件输入输出流下载word
//设置向浏览器端传送的文件格式
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
try {
response.setHeader("Content-Disposition", "attachment;fileName=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
FileInputStream is = new FileInputStream(outFile);
ServletOutputStream os = response.getOutputStream();
byte[] b = new byte[4096];
int length;
while ((length = is.read(b)) > 0) {
os.write(b, 0, length);
}
os.close();
is.close();
outFile.delete();
} catch (Exception var7) {
throw new SysException(var7);
}