2013-08-06 22 views
5

// O qualsiasi altra soluzione per salvare multipartfile in DB. Ho provato in questo modo ma ricevendo errore.Come convertire MultipartFile nel flusso di byte

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

che errore state ottenendo? –

+0

Che errore stai ottenendo? Come viene salvato nel DB (utilizzare la mappatura ORM?) Quale tipo di file Multipart sta usando (MIME, JMS, ..)? – Filip

+0

Sto provando a prendere il file immagine (png) usando la mappatura ORM funzionerà –

risposta

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// 
Problemi correlati