把上传的文件直接返回

public String RARFile(MultipartFile imageFile, HttpServletRequest request, HttpServletResponse response) throws IOException {
//        Thumbnails.of((File) imageFile).outputQuality(0.3f).outputFormat("jpg").size(100, 100);
        InputStream inputStream = imageFile.getInputStream();
        OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
        //创建存放文件内容的数组
        byte[] buff = new byte[1024];
        //所读取的内容使用n来接收
        int n;
        //当没有读取完时,继续读取,循环
        while ((n = inputStream.read(buff)) != -1) {
            //将字节数组的数据全部写入到输出流中
            outputStream.write(buff, 0, n);
        }
        outputStream.flush();
        //关流
        outputStream.close();
        inputStream.close();
        return "t";
    }

猜你喜欢

转载自www.cnblogs.com/lovetl/p/12750264.html
今日推荐