# Problem: Upload file size limit to 500KB

**URL:** <https://www.ruby-forum.com/t/problem-upload-file-size-limit-to-500kb/107041>\
**Category:** Rails\
**Created:** [June 17, 2007, 3:00am UTC](https://www.ruby-forum.com/t/problem-upload-file-size-limit-to-500kb/107041 "2007-06-17T03:00:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![homestarrunner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/71e660/32.png) [@homestarrunner](https://www.ruby-forum.com/u/homestarrunner)\
**Post date:** [June 17, 2007, 3:00am UTC](https://www.ruby-forum.com/t/problem-upload-file-size-limit-to-500kb/107041/1 "2007-06-17T03:00:05Z")

</div>

hi,

i’m sure some of you had come across this problem before, but i was  
unable to find the answer after spending quite some time searching.

i have a basic file uploader, code similar to rails recipe (or rails  
manual).

problem occurs when i try to upload files (images) greater than 500KB.  
the largest file i could upload was 493KB and i’ve uploaded a bunch  
files under 490KB and they all worked. the smallest file which i failed  
to upload is 500KB so i guess that’s where the “limit” is.

my data field in mysql is set to mediumblob, inevitably, i tried  
changing it to longblob which didn’t work.

i’m running the webrick server.

Any help would be greatly appreciated…

thx

---

<div class="post-metadata">

**Author:** ![homestarrunner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/71e660/32.png) [@homestarrunner](https://www.ruby-forum.com/u/homestarrunner)\
**Post date:** [July 16, 2007, 2:41pm UTC](https://www.ruby-forum.com/t/problem-upload-file-size-limit-to-500kb/107041/2 "2007-07-16T14:41:06Z")

</div>

mike yang wrote:

> hi,
> 
> i’m sure some of you had come across this problem before, but i was  
> unable to find the answer after spending quite some time searching.
> 
> i have a basic file uploader, code similar to rails recipe (or rails  
> manual).
> 
> problem occurs when i try to upload files (images) greater than 500KB.  
> the largest file i could upload was 493KB and i’ve uploaded a bunch  
> files under 490KB and they all worked. the smallest file which i failed  
> to upload is 500KB so i guess that’s where the “limit” is.
> 
> my data field in mysql is set to mediumblob, inevitably, i tried  
> changing it to longblob which didn’t work.
> 
> i’m running the webrick server.
> 
> Any help would be greatly appreciated…
> 
> thx

Hi

I am aware that this post is quite old. But I went through the same  
scenario as you have described above by testing different file sizes  
around 500KB. The only relevant search result I found was this thread  
with no replies. The error from rails was ActiveRecord::StatementInvalid  
and not much more info to go on besides the fact that the error was  
thrown in the MySQL adapter. After looking in my development.log I could  
actually read the error message that the MySQL server had returned. The  
problem was that the MySQL server by default did not allow incoming  
packets to be larger than 500KB. The solution is to change the  
“max\_allowed\_packet” variable in your MySQL server. Which is described  
on this link:

[http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html](http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html)

I simply created (on FreeBSD) a /etc/my.cnf and added the following two  
lines and then restarted MySQL:

[mysqld]  
max\_allowed\_packet=16M

A tried to upload a file ~14 MB and I got the same error as before. Make  
sure you have this variable set with a marginal.

Hope that helped

fluff
