天道不一定酬所有勤
但是,天道只酬勤

webx3文件下载

注:使用阿里云的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);
            }
        }

    }
(全文完)
欢迎关注HollisChuang微信公众账号
打赏

如未加特殊说明,此网站文章均为原创,转载必须注明出处。HollisChuang's Blog » webx3文件下载

分享到:更多 ()

HollisChuang's Blog

联系我关于我