webx3文件下载
webx3文件下载
酷游博客

webx3文件下载

酷游
1月22日发布 /正在检测是否收录...

注:使用阿里云的oss服务进行文件下载,使用代理将oss的下载封装起来。以下是一个screen的java类:

public void execute(
            @Param("fileName") String fileName,
            TurbineRunData rundata, Context context,HttpServletRequest req,HttpServletResponse resp) throws IOException, ServletException {

        if(StringUtils.isBlank(fileName)){
            throw new RuntimeException("Parameter can not be null!");
        }
        OSSObject ossObject = ossService.getObject(fileName);
        if(ossObject==null){
            throw new RuntimeException("there is no package for " + fileName);
        }
        OutputStream os = null;
        InputStream is = null;
        try {
            os = resp.getOutputStream();
            is = ossObject.getObjectContent();
            resp.setContentType("application/x-tar");
            resp.addHeader("Version", "1.0");
            resp.setContentLength((int) ossObject.getObjectMetadata().getContentLength());
            String filedisplay = URLEncoder.encode(fileName, "UTF-8");
            resp.addHeader("Content-Disposition", "attachment; filename=a.tgz");
            IOUtils.copy(is, os);
            os.flush();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (os != null) {
                IOUtils.closeQuietly(os);
            }
            if (is != null) {
                IOUtils.closeQuietly(is);
            }
        }

    }
© 版权声明
THE END
喜欢就支持一下吧
点赞 0 分享 赞赏
评论
当前页面的评论已关闭
易航博客
SSL