File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes uploading images using strut Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "uploading images using strut " Watch "uploading images using strut " New topic
Author

uploading images using strut

kalpana srinuvasan
Greenhorn

Joined: Jul 08, 2008
Posts: 9
hi.. i am using strut 1.3, i dont know how to upload images using struct in jsp page , after using <html:form action="/imgtest" enctype="multipart/form-data">, i can able to browse the image .but i have to store in the table with image column(in blob).
i write some code in action:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm imgtestForm = (DynaActionForm) form;// TODO Auto-generated method stub

FormFile myFile = (FormFile)imgtestForm.get("uploads");
System.out.println("sze:"+myFile.getFileSize());


byte[] ba = null;
try {
ba = myFile.getFileData();
System.out.println("dat:"+ba.length);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Service service = null;
try{
service = (Service) ServicesLocator.getInstance().lookUpService(Service.class);
}
catch (ServiceLocatorException e){
e.printStackTrace();
}

EmployeeImagesVO vo = new EmployeeImagesVO();
vo.setEmpimgbu("MSIL");
vo.setEmpimgempid("999");

//vo.setEmpimgimage(ba);

InputStream instr = myFile.getInputStream();




Blob blob = new Blob(byte[]);
//here is the problem .. i am not able to convert byte[] to Blob and not able to set to the column
vo.setEmpimgimage(blob);
service.addEmployeeImages(vo);


return null;
}
}
how to proceed further..?
please help me ..
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This link has an example of uploading a file and writing it to a BLOB using Struts.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: uploading images using strut