Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in uploading big images

 
Shrikant Kulkarni
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search for setMaxSize in this page from the FileUpload documentation:
http://jakarta.apache.org/commons/fileupload/using.html


Moving to the Other Open Source Projects forum
[ May 26, 2006: Message edited by: Ben Souther ]
 
Shrikant Kulkarni
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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");
prapredStatement.setInt(1,logId);
prapredStatement.setString(2,imageName);
// Execute the SQL statement
resultSet = prapredStatement.executeQuery();
// Retrieve Blob streams for Image column, and load the sample file
if(resultSet.next())
{
// 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= sampleFileStream.read(buffer)) != -1 ) // Read
//from file
blobOutputStream.write(buffer, 0, nread); // Write to Blob
// Close both streams
sampleFileStream.close();
blobOutputStream.close();
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic