0

I am new to the blob data conversion of content. I am reading the emails and saving into database with body type as BLOB, if we have image embed into email even those are saving into it. but the problem is retrieving back and showing it to users. The image re-creation is not happening it says image path failed.

the src in image tag would be something like this.

cid:image001.png@01CF630F.005FA080

Please help with the suitable java code which 'll form image back and we can show into the division .

thanks in advance.

user3217695
  • 65
  • 1
  • 1
  • 8

1 Answers1

1

I have solved same problem, by making a sevlet that returns the byte[] of the image. And call this servlet within the img src tag.

Example : This method will give you byte[] for any file, and method is in Utilities class

public static byte[] getFileData ( String fileName ){
    File f = new File(fileName);
    byte data [] = new byte[ (int) f.length() ];

    try {
        FileInputStream fis = new FileInputStream(f);
        fis.read(data);
        fis.close();
        return data;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}**

and I have called this method from doGet of the servlet as following:

final String imageName = request.getParameter("imageName");    
byte[] imageData = Utilities.getFileData( ROOT_DIR + imageName );
response.getOutputStream().write(imageData);

In above code ROOT_DIR is also defined as C:\Temp\FormData\Images\

My div is like this:

<div>
<img src='http://localhost:9080/LoadImage?imageName=one.png' />
</div>
Mohammad Ashfaq
  • 1,333
  • 2
  • 14
  • 38
  • I ve read email completely and saved it into data base it's complete html structure which is stored nothing like path and all.. how to convert it back with correct format which 'll display image – user3217695 Apr 29 '14 at 11:13
  • Can your email has morethan one image? – Mohammad Ashfaq Apr 29 '14 at 11:13
  • may be it's user depended and images are inline i mean not attached – user3217695 Apr 29 '14 at 11:16
  • Show me the table structure, where you have stored this images. I have idea which will work if your mail contains only one image – Mohammad Ashfaq Apr 29 '14 at 11:17
  • i am just converting the data which 'll be a html structure into a blob(bytes) and stored into DB, n since the image is also converted and saved i dont know how to reform it back, but the email content is diplayed properly , the src prepared is something like this. Description: colEnterprise – user3217695 Apr 29 '14 at 11:22
  • Meaning that your complete html is converted to blob and stored in db, am I understand it correctly? – Mohammad Ashfaq Apr 29 '14 at 11:28
  • yeah exactly the complete thing, not image in separate and content else where . – user3217695 Apr 29 '14 at 11:30
  • I have searched it and found this query "select CAST(html AS CHAR) htmllayout from formlist where id = ?". Here htmllayout is in BLOB format – Mohammad Ashfaq Apr 29 '14 at 11:54