18

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

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

2 回答 2

44
MultipartFile  file;
byte [] byteArr=file.getBytes();
InputStream inputStream = new ByteArrayInputStream(byteArr);
于 2013-08-06T10:11:48.680 回答
-2
    //Start Photo Upload with Adhaar No// 
    if (simpleLoanDto.getPic() != null && simpleLoanDto.getAdharNo() != null) {
        String ServerDirPath = globalVeriables.getAPath() + "\\";
        File ServerDir = new File(ServerDirPath);
        if (!ServerDir.exists()) {
            ServerDir.mkdirs();
        }
        // Giving File operation permission for LINUX//
        IOperation.setFileFolderPermission(ServerDirPath);
        MultipartFile originalPic = simpleLoanDto.getPic();
        byte[] ImageInByte = originalPic.getBytes();
        FileOutputStream fosFor = new FileOutputStream(
                new File(ServerDirPath + "\\" + simpleLoanDto.getAdharNo() + "_"+simpleLoanDto.getApplicantName()+"_.jpg"));
        fosFor.write(ImageInByte);
        fosFor.close();
    }
    //End  Photo Upload with Adhaar No// 
于 2017-06-22T19:16:49.610 回答