如何将MultipartFile转换为字节流 [英] How to convert MultipartFile into byte stream

查看:15375
本文介绍了如何将MultipartFile转换为字节流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//或者将多部分文件保存到数据库中的其他解决方案。
我以这种方式尝试,但得到错误。

//Or any other solution to saving multipartfile into DB. I tried with this way but getting error.

File fileOne = new File("file.getOrignalFileName");//what should be kept inside this method 
        byte[] bFile = new byte[(int) fileOne.length()];
        try {
            FileInputStream fileInputStream = new FileInputStream(fileOne);
            //convert file into array of bytes
            fileInputStream.read(bFile);
            fileInputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        questionDao.saveImage(bFile);
}


推荐答案

MultipartFile  file;
byte [] byteArr=file.getBytes();
InputStream inputStream = new ByteArrayInputStream(byteArr);

这篇关于如何将MultipartFile转换为字节流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆