2013-08-06 123 views
5

//マルチパートファイルをDBに保存するための他の解決方法。 私はこの方法で試しましたが、エラーが発生しました。MultipartFileをバイトストリームに変換する方法

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); 
} 
+0

あなたはどのようなエラーを取得していますか? –

+0

あなたはどんなエラーを受けていますか?どのようにMultipartファイル(MIME、JMSなど)を使用していますか? – Filip

+0

ORMマッピングを使用してイメージファイル(png)を取得しようとしています –

答えて

16
MultipartFile file; 
byte [] byteArr=file.getBytes(); 
InputStream inputStream = new ByteArrayInputStream(byteArr); 
-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// 
関連する問題