# Unable to upload larger files

**URL:** <https://www.ruby-forum.com/t/unable-to-upload-larger-files/194331>\
**Category:** Rails\
**Created:** [September 2, 2010, 3:08pm UTC](https://www.ruby-forum.com/t/unable-to-upload-larger-files/194331 "2010-09-02T15:08:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [September 2, 2010, 3:08pm UTC](https://www.ruby-forum.com/t/unable-to-upload-larger-files/194331/1 "2010-09-02T15:08:29Z")

</div>

hii,  
i am trying to upload some files to filesystem using rails application  
when i use small size file everything is perfect but i when goes for  
larger files i got error  
this is my code

#this model file  
class DataFile \< ActiveRecord::Base

def self.save(upload)  
name = upload[‘datafile’].original\_filename  
directory = “[//192.168.147.17/Smruti/streams](https://192.168.147.17/Smruti/streams)”  
# create the file path  
path = File.join(directory, name)  
# write the file  
File.open(path, “wb”) { |f| f.write(upload[‘datafile’].read) }  
end  
end

#this is my controller  
class UploadController \< ApplicationController  
def index  
render :file =\> ‘app\views\upload\uploadfile.rhtml’  
end  
def uploadFile  
post = DataFile.save(params[:upload])  
render :text =\> “File has been uploaded successfully”  
end  
end

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [September 2, 2010, 3:09pm UTC](https://www.ruby-forum.com/t/unable-to-upload-larger-files/194331/2 "2010-09-02T15:09:24Z")

</div>

Amit T. wrote:

> hii,  
> i am trying to upload some files to filesystem using rails application  
> when i use small size file everything is perfect but i when goes for  
> larger files i got error  
> this is my code
> 
> #this model file  
> class DataFile \< ActiveRecord::Base
> 
> def self.save(upload)  
> name = upload[‘datafile’].original\_filename  
> directory = “[//192.168.147.17/Smruti/streams](https://192.168.147.17/Smruti/streams)”  
> # create the file path  
> path = File.join(directory, name)  
> # write the file  
> File.open(path, “wb”) { |f| f.write(upload[‘datafile’].read) }  
> end  
> end
> 
> #this is my controller  
> class UploadController \< ApplicationController  
> def index  
> render :file =\> ‘app\views\upload\uploadfile.rhtml’  
> end  
> def uploadFile  
> post = DataFile.save(params[:upload])  
> render :text =\> “File has been uploaded successfully”  
> end  
> end

app/models/data\_file.rb:9:in `write' app/models/data_file.rb:9:in `save’  
app/models/data\_file.rb:9:in `open' app/models/data_file.rb:9:in `save’  
app/controllers/upload\_controller.rb:6:in `uploadFile' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `send’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/base.rb:1253:in  
`perform_action_without_filters' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:617:in `call\_filters’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/filters.rb:610:in  
`perform_action_without_benchmark' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform\_action\_without\_rescue’  
C:/InstantRails-2.0-win/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform\_action\_without\_rescue’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/rescue.rb:136:in  
`perform_action_without_caching' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:13:in `perform\_action’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/query\_cache.rb:34:in  
`cache' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/query_cache.rb:8:in `cache’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/caching/sql\_cache.rb:12:in  
`perform_action' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `send’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/base.rb:524:in  
`process_without_filters' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:606:in `process\_without\_session\_management\_support’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/session\_management.rb:134:in  
`process' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:392:in `process’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/dispatcher.rb:183:in  
`handle_request' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:110:in `dispatch\_unlocked’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/dispatcher.rb:123:in  
`dispatch' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `synchronize’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/dispatcher.rb:122:in  
`dispatch' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:132:in `dispatch\_cgi’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/dispatcher.rb:39:in  
`dispatch' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:76:in `process’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in  
`synchronize' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in `process’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:159:in  
`process_client' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in `each’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in  
`process_client' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `run’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in  
`initialize' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `new’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in  
`run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `initialize’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in  
`new' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `run’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:282:in  
`run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in `each’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in  
`run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:128:in `run’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/command.rb:212:in  
`run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:281 C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load\_without\_new\_constant\_marking’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active\_support/dependencies.rb:142:in  
`load' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new\_constants\_in’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active\_support/dependencies.rb:142:in  
`load' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/servers/mongrel.rb:64 C:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem\_original\_require’  
C:/InstantRails-2.0-win/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`require' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active\_support/dependencies.rb:521:in  
`new_constants_in' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49  
C:/InstantRails-2.0-win/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' C:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’  
script/server:3

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [September 7, 2010, 9:31am UTC](https://www.ruby-forum.com/t/unable-to-upload-larger-files/194331/3 "2010-09-07T09:31:32Z")

</div>

Quoting Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> hii,  
> i am trying to upload some files to filesystem using rails application  
> when i use small size file everything is perfect but i when goes for  
> larger files i got error  
> this is my code

Check the Webserver’s (e.g. Apache) file size limit. It may be set to  
some  
small value.

HTH,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [September 7, 2010, 10:09am UTC](https://www.ruby-forum.com/t/unable-to-upload-larger-files/194331/4 "2010-09-07T10:09:47Z")

</div>

Jeffrey L. Taylor wrote:

> Quoting Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > hii,  
> > i am trying to upload some files to filesystem using rails application  
> > when i use small size file everything is perfect but i when goes for  
> > larger files i got error  
> > this is my code
> 
> Check the Webserver’s (e.g. Apache) file size limit. It may be set to  
> some  
> small value.
> 
> HTH,  
> Jeffrey

Thanks for responding Jeffrey

but i am new to rails ,so where do i find Webserver file size limit ,am  
running  
mongrel as server and one more thing i would like to mention is when am  
trying to upload large file (320 mb),file is being uploaded to phyical  
location but i am getting error like

Invalid argument -  
[//192.168.147.27/Smruti/streams/predator\_720x480\_5mbps\_30fps\_17minclip.264.filepart](https://192.168.147.27/Smruti/streams/predator_720x480_5mbps_30fps_17minclip.264.filepart)

When i looked into the streams folder file is there…

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [September 7, 2010, 3:47pm UTC](https://www.ruby-forum.com/t/unable-to-upload-larger-files/194331/5 "2010-09-07T15:47:27Z")

</div>

is that your app? what are you using to handle downloads?

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [September 7, 2010, 4:06pm UTC](https://www.ruby-forum.com/t/unable-to-upload-larger-files/194331/6 "2010-09-07T16:06:12Z")

</div>

Quoting Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > some  
> > trying to upload large file (320 mb),file is being uploaded to phyical  
> > location but i am getting error like
> 
> Invalid argument -  
> [//192.168.147.27/Smruti/streams/predator\_720x480\_5mbps\_30fps\_17minclip.264.filepart](https://192.168.147.27/Smruti/streams/predator_720x480_5mbps_30fps_17minclip.264.filepart)
> 
> When i looked into the streams folder file is there…

I don’t know Mongrel, but I’d look in the Mongrel configuration file. I  
expect Mongrel is cutting off or aborting the file transfer and then  
throwing  
the InvalidArgument exception.

In Nginx, the setting is:

```
    client_max_body_size 0; # don't limit the upload file size

```

In Apache, the setting is:

```
LimitRequestBody 500000

```

Look for something similar.

HTH,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [September 8, 2010, 10:35am UTC](https://www.ruby-forum.com/t/unable-to-upload-larger-files/194331/7 "2010-09-08T10:35:36Z")

</div>

Jeffrey L. Taylor wrote:

> Quoting Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > > some  
> > > trying to upload large file (320 mb),file is being uploaded to phyical  
> > > location but i am getting error like
> > 
> > Invalid argument -  
> > [//192.168.147.27/Smruti/streams/predator\_720x480\_5mbps\_30fps\_17minclip.264.filepart](https://192.168.147.27/Smruti/streams/predator_720x480_5mbps_30fps_17minclip.264.filepart)
> > 
> > When i looked into the streams folder file is there…
> 
> I don’t know Mongrel, but I’d look in the Mongrel configuration file. I  
> expect Mongrel is cutting off or aborting the file transfer and then  
> throwing  
> the InvalidArgument exception.
> 
> In Nginx, the setting is:
> 
> ```
> client_max_body_size 0; # don't limit the upload file size
> 
> ```
> 
> In Apache, the setting is:
> 
> ```
> LimitRequestBody 500000
> 
> ```
> 
> Look for something similar.
> 
> HTH,  
> Jeffrey

Jeffrey i edit the code and things starts working for me

#this model file  
class DataFile \< ActiveRecord::Base

def self.save(upload)  
name = upload[‘datafile’].original\_filename  
directory = “c:/dm”  
# create the file path  
path = File.join(directory, name)  
# write the file  
File.open(path, “wb”) { |f| f.write(upload[‘datafile’].read) }

target=“[//192.168.147.17/Smruti/streams](https://192.168.147.17/Smruti/streams)”  
File.copy(path,target)

end  
end  
i added two lines  
target=“[//192.168.147.17/Smruti/streams](https://192.168.147.17/Smruti/streams)”  
File.copy(path,target)  
ans i changed  
directory = “c:/dm”  
and things are working for me  
but could you tell me what was happening before why am getting  
Invalid argument -

> [//192.168.147.27/Smruti/streams/predator\_720x480\_5mbps\_30fps\_17minclip.264.filepart](https://192.168.147.27/Smruti/streams/predator_720x480_5mbps_30fps_17minclip.264.filepart)

---

<div class="post-metadata">

**Author:** ![amit-singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@amit-singh](https://www.ruby-forum.com/u/amit-singh)\
**Post date:** [September 8, 2010, 8:18am UTC](https://www.ruby-forum.com/t/unable-to-upload-larger-files/194331/8 "2010-09-08T08:18:36Z")

</div>

radhames brito wrote:

> is that your app? what are you using to handle downloads?

Am not doing any downloads.I am just trying to upload and for that i  
wrote the  
code above .I also mentioned the error that i got .
