File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Problem in uploading big images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Problem in uploading big images" Watch "Problem in uploading big images" New topic

Problem in uploading big images

Shrikant Kulkarni
Ranch Hand

Joined: May 10, 2005
Posts: 42

I am using apache's FileUpload to upload images into the data base. I am using oracle 10g data base and image is stored as a BLOB object. I am connecting to the DB using JDBC thin drive.
I can upload small images of below 4KB but bigger than that.
When I wanted to upload some big images of size 50-100KB, i am getting "Data size is bigger then max size".

Any help please.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Search for setMaxSize in this page from the FileUpload documentation:

Moving to the Other Open Source Projects forum
[ May 26, 2006: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Shrikant Kulkarni
Ranch Hand

Joined: May 10, 2005
Posts: 42
I have solved this problem by inserting empty_blob() while inserting the BLOB image. Retrieve the row just inserted, and lock it for insertion of the BLOB columns.
prapredStatement = connection.prepareStatement("select image from image_upload where log_id = ? and image_name = ? for update");
// Execute the SQL statement
resultSet = prapredStatement.executeQuery();
// Retrieve Blob streams for Image column, and load the sample file
// Get the Blob locator and open output stream for the Blob
Blob mapBlob = resultSet.getBlob(1);
OutputStream blobOutputStream = ((oracle.sql.BLOB)mapBlob).getBinaryOutputStream();
// Open the FileInputStream for insertion into the Blob column
// saveTo is File from which where you are getting the image
InputStream sampleFileStream = new FileInputStream(saveTo);
// Buffer to hold chunks of data to being written to the Blob.
byte[] buffer = new byte[10* 1024];
// Read a chunk of data from the sample file input stream, and write the chunk to the Blob column output stream.
//Repeat till file has been fully read.
int nread = 0; // Number of bytes read
while( (nread= != -1 ) // Read
//from file
blobOutputStream.write(buffer, 0, nread); // Write to Blob
// Close both streams
I agree. Here's the link:
subject: Problem in uploading big images
It's not a secret anymore!