双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

请教一下我这段文件下载的代码是否有问题

白白了白呀白 白白了白呀白 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用浏览器测试能弹窗下载,但是用postman测试用send and down 我后台打印流已经写完,但是postman却一直卡住

@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);
}
}
...全文

相关推荐

Java程序部署到服务器上,接口请求下载文件失败/文件为空/文件名不对的问题

主要介绍了Java程序部署到服务器上,接口请求下载文件失败/文件为空/文件名不对,本文给大家分享错误原因及解决方法,需要的朋友可以参考下

weixin_38506852

asp.net 文件下载实现代码

件下载代码,Copy 别人的.需要的朋友可以参考下。

weixin_38698590

php下载文件的代码示例

复制代码 代码如下: <?php $file = ‘monkey.gif’; if (file_exists($file)) { header(‘Content-Description: File Transfer’); header(‘Content-Type: application/octet-stream’); header(‘Content-Disposition: attachment; filename=’.basename($file)); header(‘Content-Transfer-Encoding: binary’); header(‘Expires: 0’); he

weixin_38615591

下载代码

public void download3(String a,String d){ String s1 = "http://58.177.123.82:9080"+a; InputStream is = null; //定义一个输入流。 BufferedInputStream bis = null;//定义一个带缓冲的输入流 。 try{ URL url = new URL(s1);//创建一个URL对象。 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); System.out.println(); conn.setDoInput(true); conn.connect(); is = conn.getInputStream();//打开到此 URL 的连接并返回一个用于从该连接读入的 InputStream。 bis = new BufferedInputStream(is); }catch(Exception e){ System.out.println(e.toString()); } //写到本地 BufferedOutputStream bos = null; //定义一个带缓冲的输出流。 File file = new File("/sdcard/"+d); System.out.println(file.exists()); if (file.exists()){ Toast.makeText(Reader5.this, "sorry! the file is exists", Toast.LENGTH_LONG).show(); } else{ try{ bos = new BufferedOutputStream(new FileOutputStream(file));; int num = -1; byte[] buffer = new byte[1024]; while (true) { num = bis.read(buffer); if (num == -1) { bos.flush(); break; } bos.write(buffer, 0, num); bos.flush(); } bos.close(); bis.close(); bos = null; bis = null; if( file.exists()){ Toast.makeText(Reader5.this, "download success!", Toast.LENGTH_LONG).show(); } }catch(Exception e){ } } }

ye06063223

PHP——文件下载

这个代码是用来用户php文件下载的,挺不错,大家可以用用,很好用的啊

niaho3020484
评论 1
收藏 已收藏
分享
返回顶部
白白了白呀白
Web 开发 81,108 成员 341,720 内容