首页 > Web开发 > 详细

FastDFS上传返回的url直接下载和下载文件的文件名问题

时间:2019-09-11 15:46:35      阅读:1553      评论:0      收藏:0      [点我收藏+]
直接调用FastDFS返回的url,浏览器访问后默认打开方式。
/usr/bin/fdfs_test /etc/fdfs/client.conf upload test.jpg

技术分享图片

 

 

 文件下载方案

 1.调用download接口,定义下载的文件名

public void  download(String fileUrl, HttpServletResponse response) throws Exception{

byte[] data = fdfsClient.download(fileUrl);

response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("test.7z", "UTF-8"));

// 写出
ServletOutputStream outputStream = response.getOutputStream();
IOUtils.write(data, outputStream);
}

2.nginx反向代理增加请求头Content-disposition及attachment

   server {
  listen 8082;
  server_name 192.168.8.200;
  location /group1/M00 {
    add_header Content-Disposition "attachment;filename=$arg_attname"; 
    ngx_fastdfs_module;
  }
  }

在upload接口中进行url拼接
fdfsClient.uploadFile(file) + "?attname=" + file.getOriginalFilename()

FastDFS上传返回的url直接下载和下载文件的文件名问题

原文:https://www.cnblogs.com/jxd283465/p/11506568.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!