一尘不染

如何将MultipartFile转换为字节流

hibernate

//或将多部分文件保存到数据库的任何其他解决方案。我尝试用这种方式,但出现错误。

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);

阅读 3256

收藏
2020-06-20

共1个答案

一尘不染

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