Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to store image object

 
wesley arun
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Pals,

Well i have a jsp application to capture some data and store it in the oracle DB, but i need some image object to capture along with the existing data.

Do i have to create a blob object in my oracle DB, and if so how to insert the image object. Or is there anyway i can store it in the webserver, if so how.


I will be grateful if anybody help me in this regards.

Thanks In Advance
Wesley

 
Ram Para
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first option
You can upload and save images to a folder. No need to put images in DB.

second option
You can create a blob in DB and write the binaries in it.


 
wesley arun
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ram,

well can you give me a sample code how to accomplish both the option.


Wesley
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#2 is covered in the JDBC tutorial. #1 is just Java code. What are you looking for, the File I/O libraries?
 
Ram Para
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an Struts code for file upload.

Here I am saving the file to an directory. You can change the path to some other folder. like in C:\abc folder

You can easily modify the code.

try this


DynaActionForm dynaForm = (DynaActionForm) form;
FormFile fileForUpload = (FormFile) dynaForm.get("fileToUpload");
String path = request.getSession().getServletContext().getRealPath(FILE_UPLOAD_PATH);
path = uploadExcelSheet(path, fileForUpload);


private String uploadExcelSheet(String path, FormFile fileForUpload){
try {
String fileName = fileForUpload.getFileName();

File f = new File(path);
if (!f.isDirectory()) {
f.mkdir();
}
InputStream stream = fileForUpload.getInputStream();
path += "/" + fileName;
OutputStream bos = new FileOutputStream(path);
int temp = 0;

byte[] buffer = new byte[8192];
while ((temp = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, temp);
}

bos.close();
stream.close();

}catch(IOException ioEx){

}
return path;
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic