wood burning stoves 2.0*
The moose likes Struts and the fly likes File Upload Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "File Upload Question" Watch "File Upload Question" New topic
Author

File Upload Question

djordje vasilic
Greenhorn

Joined: Aug 10, 2006
Posts: 6
Hi all, I'm struts newbie and this is my first post here



I'm using struts file upload to insert jpg images into MySQL database, and everything works fine as long as I dont try to insert "bigger" files (dont know exactly, but it works with 28k jpg image, and doesnt work with 70k for example).

These are the errors I get:
javax.servlet.ServletException: Data truncation: Data too long for column 'image' at row 1
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'image' at row 1

I know that there is way to set maximum size of uploaded files in struts-config file, but the results were the same whatever I put for "maxFileSize".

Am I missing something, anyone had experienced similar problem?

Thanks in advance.
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
I think you have to validate the size on the server side somewhere, either in form validation or in your action.

Edit:
I did some investigation and found an attribute, I don't have time to test it, but you can give it a try:
Add to struts-config
<controller processorClass="org.apache.struts.action.RequestProcessor" maxFileSize="2M"/>

It should accept K, M or G. (kilo, mega, or giga).

Edit again:
Found more info here, looks like it should work:
http://struts.apache.org/1.x/userGuide/configuration.html
[ August 10, 2006: Message edited by: Dom Lassy ]
djordje vasilic
Greenhorn

Joined: Aug 10, 2006
Posts: 6
Cheers mate, I'll give it a try and will let you know what happened.
djordje vasilic
Greenhorn

Joined: Aug 10, 2006
Posts: 6
Nothing happened

Any other ideas maybe?
djordje vasilic
Greenhorn

Joined: Aug 10, 2006
Posts: 6
"maxFileSize" is by defeault 250M so I guess that shouldnt be a problem.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
dj,

We're glad you dropped by the Java Ranch. There aren't many rules here, but we do ask that you let us know who you are by giving us your actual first and last names. Please make sure the "publicly displayed name" in your profile meets the JavaRanch naming policy.


Merrill
Consultant, Sima Solutions
djordje vasilic
Greenhorn

Joined: Aug 10, 2006
Posts: 6
profile updated, sorry about that
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you will take a moment to look at the struts-examples.war file that comes with the Struts download, you will see an example of an upload that verifies that the uploaded file is below a certain size limit before allowing the upload. Just study the source code, and you will see how it's done.
djordje vasilic
Greenhorn

Joined: Aug 10, 2006
Posts: 6
Problem wasn't about struts, it was more related with MySQL - using LONGBLOB instead of BLOB solves the problem for me, as I dont need to upload files bigger than 1M

Thanks anyway
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: File Upload Question