# Failed to allocate memory while downloading large files

**URL:** <https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900>\
**Category:** Mongrel\
**Created:** [September 13, 2010, 12:33pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900 "2010-09-13T12:33:00Z")\
**Posts on this page:** 19\
**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 13, 2010, 12:33pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/1 "2010-09-13T12:33:00Z")

</div>

hii ,  
I uploaded 1 GB of file to filesystem,but now when i trying to  
download this 1 GB of file ,i am getting failed to allocate memory.  
am running mongrel as server in development mode.

NoMemoryError (failed to allocate memory):  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active\_support/cache.rb:60:in  
`<<' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/cache.rb:60:in`expand\_cache\_key’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/response.rb:118:in  
`etag=' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/response.rb:148:in`handle\_conditional\_get!’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/response.rb:138:in  
`prepare!' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:532:in`send\_response’  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/base.rb:526: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\_ma  
gement\_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/bin/../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/bin/…/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/bin/../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\_cons  
nt\_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

ndered  
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action\_controller/templates/rescues/\_trace  
(250.0ms)

---

<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 13, 2010, 3:58pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/2 "2010-09-13T15:58:44Z")

</div>

On Mon, Sep 13, 2010 at 7:33 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> hii ,  
> I uploaded 1 GB of file to filesystem,but now when i trying to  
> download this 1 GB of file ,i am getting failed to allocate memory.  
> am running mongrel as server in development mode.
> 
> NoMemoryError (failed to allocate memory):  
> C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active\_support/cache.rb:60:in  
> `<<' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/cache.rb:60:in `expand\_cache\_key’

This has nothing to do with Mongrel.

> From the backtrace it seems you’re trying to cache all the file  
> contents in memory.

## What is the code you’re using to serve the file? Mongrel is quite capable to serve any file from public folder without any Rails code interfering it.

## Luis L. AREA 17

Perfection in design is achieved not when there is nothing more to add,  
but rather when there is nothing more to take away.  
Antoine de Saint-Exupéry

---

<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 14, 2010, 7:49am UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/3 "2010-09-14T07:49:55Z")

</div>

Luis L. wrote:

> On Mon, Sep 13, 2010 at 7:33 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > hii ,  
> > ? ? ?I uploaded 1 GB of file to filesystem,but now when i trying to  
> > download this 1 GB of file ,i am getting failed to allocate memory.  
> > am running mongrel as server in development mode.
> > 
> > NoMemoryError (failed to allocate memory):  
> > ?C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active\_support/cache.rb:60:in  
> > `<<' ?C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/cache.rb:60:in `expand\_cache\_key’
> 
> This has nothing to do with Mongrel.
> 
> > From the backtrace it seems you’re trying to cache all the file  
> > contents in memory.
> 
> ## What is the code you’re using to serve the file? Mongrel is quite capable to serve any file from public folder without any Rails code interfering it.
> 
> ## Luis L. AREA 17
> 
> Perfection in design is achieved not when there is nothing more to add,  
> but rather when there is nothing more to take away.  
> Antoine de Saint-Exupé²¹

Luis ,this is how am downloading my files

send\_data(@data,:filename =\> @containerformat.name+extension,  
:disposition =\> ‘attachment’)  
but i am getting error failed to allocate memory for large files ,for  
small files it’s working fine

and one thing more i observed while uploading large files , whenever i  
upload data more than 2gb from IE OR from mozila ,both restarts but for  
google chorme its working fine???

---

<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 14, 2010, 1:47pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/4 "2010-09-14T13:47:37Z")

</div>

On Tue, Sep 14, 2010 at 2:49 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Luis ,this is how am downloading my files
> 
> send\_data(@data,:filename =\> @containerformat.name+extension,  
> :disposition =\> ‘attachment’)  
> but i am getting error failed to allocate memory for large files ,for  
> small files it’s working fine

Because send\_data will try to load the whole file in memory.

> **[ActionController::Streaming#send\_data - APIdock](https://apidock.com/rails/ActionController/Streaming/send_data)**
>
> ActionController::Streaming#send\_data - Ruby on Rails API documentation. View source code and usage examples.

Since the file is not dynamically generated, serve it directly, don’t  
put it behind Rails.

> and one thing more i observed while uploading large files , whenever i  
> upload data more than 2gb from IE OR from mozila ,both restarts but for  
> google chorme its working fine???

## Neither IE or Mozilla do chunked uploads. Chrome does and mongrels properly streams the chunked upload to a temporary file.

## Luis L. AREA 17

Perfection in design is achieved not when there is nothing more to add,  
but rather when there is nothing more to take away.  
Antoine de Saint-Exupéry

---

<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 14, 2010, 2:29pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/5 "2010-09-14T14:29:46Z")

</div>

On Tue, Sep 14, 2010 at 9:21 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> thanks luis  
> but could you please explain how i serve it directly

Place the file inside public, provide the URL to the file as a link,  
your browser will start download once the file is served.

send\_data is not recommended for big file serving.

> and for my  
> application i can’nt use IE because as you said it don’t do chunked  
> upload.

## Can’t help you on that, please research about it.

## Luis L. AREA 17

Perfection in design is achieved not when there is nothing more to add,  
but rather when there is nothing more to take away.  
Antoine de Saint-Exupéry

---

<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 14, 2010, 2:39pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/6 "2010-09-14T14:39:10Z")

</div>

Luis L. wrote:

> On Tue, Sep 14, 2010 at 9:21 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > thanks luis  
> > but could you please explain how i serve ?it directly
> 
> Place the file inside public, provide the URL to the file as a link,  
> your browser will start download once the file is served.
> 
> send\_data is not recommended for big file serving.
> 
> > and for my  
> > application i can’nt use ?IE because as you said it don’t ?do chunked  
> > upload.
> 
> ## Can’t help you on that, please research about it.
> 
> ## Luis L. AREA 17
> 
> Perfection in design is achieved not when there is nothing more to add,  
> but rather when there is nothing more to take away.  
> Antoine de Saint-Exupé²¹

sorry luis but i didn’t get you  
i uploaded my file in filesystem than how can i place file in public  
folder  
could you please give some example??

---

<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 14, 2010, 2:21pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/7 "2010-09-14T14:21:36Z")

</div>

Luis L. wrote:

> On Tue, Sep 14, 2010 at 2:49 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Luis ,this is how am downloading my files
> > 
> > send\_data(@data,:filename =\> @containerformat.name+extension,  
> > ? ? ? ?:disposition =\> ‘attachment’)  
> > but i am getting error failed to allocate memory for large files ,for  
> > small files it’s working fine
> 
> Because send\_data will try to load the whole file in memory.
> 
> [http://apidock.com/rails/ActionController/Streaming/send\_data](http://apidock.com/rails/ActionController/Streaming/send_data)
> 
> Since the file is not dynamically generated, serve it directly, don’t  
> put it behind Rails.
> 
> > and one thing more i observed while uploading large files , whenever i  
> > upload data more than 2gb from IE OR from mozila ,both restarts but for  
> > google chorme its working fine???
> 
> ## Neither IE or Mozilla do chunked uploads. Chrome does and mongrels properly streams the chunked upload to a temporary file.
> 
> ## Luis L. AREA 17
> 
> Perfection in design is achieved not when there is nothing more to add,  
> but rather when there is nothing more to take away.  
> Antoine de Saint-Exupé²¹

thanks luis  
but could you please explain how i serve it directly and for my  
application i can’nt use IE because as you said it don’t do chunked  
upload.

thanks again

---

<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 14, 2010, 2:46pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/8 "2010-09-14T14:46:10Z")

</div>

On Tue, Sep 14, 2010 at 9:39 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> sorry luis but i didn’t get you  
> i uploaded my file in filesystem than how can i place file in public  
> folder  
> could you please give some example??

Are you using a plugin to manage your uploads? How are you saving the  
file?

Take the temporary file and use File.move or FileUtils.mv, wonder what  
are you doing right now for that.

## Please use google to search, there are plenty of file uploading tutorials about Ruby on Rails on the internet covering “do from scratch” or using gem/plugins.

## Luis L. AREA 17

Perfection in design is achieved not when there is nothing more to add,  
but rather when there is nothing more to take away.  
Antoine de Saint-Exupéry

---

<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 14, 2010, 3:03pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/9 "2010-09-14T15:03:36Z")

</div>

Amit T. wrote:

> > > Perfection in design is achieved not when there is nothing more to add,  
> > > but rather when there is nothing more to take away.  
> > > Antoine de Saint-Exupé²¹
> 
> luis i put file in public folder but now i have four copies of same file  
> one is mongel temp file ,2nd cgi file,3rd in filesyste and 4th in  
> public  
> for large don’t you think its not efficient approch  
> ??

---

<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 14, 2010, 2:50pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/10 "2010-09-14T14:50:21Z")

</div>

Luis L. wrote:

> On Tue, Sep 14, 2010 at 9:39 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > sorry luis but i didn’t get you  
> > i uploaded my file in filesystem than how ?can ?i place file in public  
> > folder  
> > could you please give some example??
> 
> Are you using a plugin to manage your uploads? How are you saving the  
> file?
> 
> Take the temporary file and use File.move or FileUtils.mv, wonder what  
> are you doing right now for that.
> 
> ## Please use google to search, there are plenty of file uploading tutorials about Ruby on Rails on the internet covering “do from scratch” or using gem/plugins.
> 
> ## Luis L. AREA 17
> 
> Perfection in design is achieved not when there is nothing more to add,  
> but rather when there is nothing more to take away.  
> Antoine de Saint-Exupé²¹

this is how am uploading  
def upload(params)

```
    path = get_path(params)
    File.open(path, "wb") do |f|
    while buff= params[:location].read(4096)

    f.write(buff)
    end
    end

```

end

def get\_path(params)  
name = params[:location].original\_filename  
directory = “[//192.168.247.77/Smruti/streams](https://192.168.247.77/Smruti/streams)”  
path = File.join(directory, name)  
return path  
end

def copyFile(uploaded\_file)  
@uploaded\_file = uploaded\_file  
directory = “[//192.168.147.17/Smruti/streams](https://192.168.147.17/Smruti/streams)”  
#url\_dir = “data”  
url\_dir = “[//192.168.147.17/Smruti/streams](https://192.168.147.17/Smruti/streams)”  
name = File.basename(@uploaded\_file)  
path = File.join(directory, name)  
if (!FileTest.exist?(path))  
FileUtils.copy @uploaded\_file, path  
else  
return “duplicate”  
end

```
        url = File.join(url_dir, name)
        return url

  end

```

end  
and after copying it filesystem

---

<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 14, 2010, 3:18pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/11 "2010-09-14T15:18:56Z")

</div>

Luis L. wrote:

> On Tue, Sep 14, 2010 at 9:50 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > ? ? ? ?end  
> > end
> 
> That is copying the file every 4k for you, you can simply File.move  
> form the temporay filename to the final name in your remote location.
> 
> It is expected you dispose the temporary file when you’re done with it.
> 
> ## Please see how proper file uploading and processing is done with Ruby on Rails.
> 
> ## Luis L. AREA 17
> 
> Perfection in design is achieved not when there is nothing more to add,  
> but rather when there is nothing more to take away.  
> Antoine de Saint-Exupé²¹

Thanks luis  
you said right ,i have to check how uploading takes place..  
could you suggest some documnet ??

---

<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 14, 2010, 3:13pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/12 "2010-09-14T15:13:41Z")

</div>

On Tue, Sep 14, 2010 at 9:50 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> end
> 
> ```
> 
> end

That is copying the file every 4k for you, you can simply File.move  
form the temporay filename to the final name in your remote location.

It is expected you dispose the temporary file when you’re done with it.

## Please see how proper file uploading and processing is done with Ruby on Rails.

## Luis L. AREA 17

Perfection in design is achieved not when there is nothing more to add,  
but rather when there is nothing more to take away.  
Antoine de Saint-Exupéry

---

<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 14, 2010, 4:14pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/13 "2010-09-14T16:14:29Z")

</div>

Luis L. wrote:

> On Tue, Sep 14, 2010 at 10:18 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Thanks luis  
> > you said right ,i have to check how uploading takes place..  
> > could you suggest some documnet ??
> 
> Google is your friend, “Rails File upload”
> 
> [Rails File Uploading 101](http://www.rubyinside.com/rails-file-uploading-101-406.html)
> 
> And others.
> 
> If the files are located in a remote server that is not in public  
> directory, then you will not have alternative but use something like  
> apache to serve map the files to the remote disk and serve them.
> 
> ## But please, avoid send\_data at any cost, and even the file reading/writing you’re doing, because with the size you’re working, you’re just slowing your application with IO operations.
> 
> ## Luis L. AREA 17
> 
> Perfection in design is achieved not when there is nothing more to add,  
> but rather when there is nothing more to take away.  
> Antoine de Saint-Exupé²¹

luis ,but do n’t have option other than send\_data and one thing i can do  
is while downloading large files i can do it in chunks but i only  
download 4096 byte ,this is my code

File.open(@containerformat.location,“rb”)do  
|f| @data = f.read(4096) end

```
  ext = File.extname(@containerformat.streamName)

    send_data(@data,:filename => name+extension,
    :disposition => 'attachment')

```

end  
what happening here..

---

<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 14, 2010, 5:04pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/14 "2010-09-14T17:04:57Z")

</div>

On Tue, Sep 14, 2010 at 11:14 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> luis ,but do n’t have option other than send\_data and one thing i can do  
> is while downloading large files i can do it in chunks but i only  
> download 4096 byte ,this is my code

please read about streaming data without loading all the file contents.

You will need to either use rack directly or create a mongrel handler  
to serve these files outside rails.

Rails can only deliver one full request meaning it will load the full  
file before completing.

## – Luis L. AREA 17

Perfection in design is achieved not when there is nothing more to add,  
but rather when there is nothing more to take away.  
Antoine de Saint-Exupéry

---

<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 14, 2010, 3:40pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/15 "2010-09-14T15:40:02Z")

</div>

On Tue, Sep 14, 2010 at 10:18 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Thanks luis  
> you said right ,i have to check how uploading takes place..  
> could you suggest some documnet ??

Google is your friend, “Rails File upload”

> **[Rails File Uploading 101](https://rubyinside.com/rails-file-uploading-101-406.html)**
>
> Mike Clark has put together a stunningly simple tutorial covering how to create a complete file uploading and image resizing system in mere minutes using Rick Olson's attachment\_fu plugin. What impresses me the most is that he shows how attachment\_fu...

And others.

If the files are located in a remote server that is not in public  
directory, then you will not have alternative but use something like  
apache to serve map the files to the remote disk and serve them.

## But please, avoid send\_data at any cost, and even the file reading/writing you’re doing, because with the size you’re working, you’re just slowing your application with IO operations.

## Luis L. AREA 17

Perfection in design is achieved not when there is nothing more to add,  
but rather when there is nothing more to take away.  
Antoine de Saint-Exupéry

---

<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 14, 2010, 5:22pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/16 "2010-09-14T17:22:50Z")

</div>

Sorry i think am taking lot of your time

---

<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 14, 2010, 5:11pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/17 "2010-09-14T17:11:08Z")

</div>

Luis L. wrote:

> On Tue, Sep 14, 2010 at 11:14 AM, Amit T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > luis ,but do n’t have option other than send\_data and one thing i can do  
> > is while downloading large files i can do it in chunks but i only  
> > download 4096 byte ,this is my code
> 
> please read about streaming data without loading all the file contents.
> 
> You will need to either use rack directly or create a mongrel handler  
> to serve these files outside rails.
> 
> Rails can only deliver one full request meaning it will load the full  
> file before completing.
> 
> ## – Luis L. AREA 17
> 
> Perfection in design is achieved not when there is nothing more to add,  
> but rather when there is nothing more to take away.  
> Antoine de Saint-Exupé²¹

```
  File.open(@containerformat.location,"rb") do |f|
  pos=f.tell
  while @buffer = f.read(4096)

  ext = File.extname(@containerformat.streamName)

  if ext == ''
    extension = File.extname(@containerformat.location)

    #send_to_web_app(pos, buffer)

    send_data(@buffer,:filename => @containerformat.name+extension,
    :disposition => 'attachment')

  else

  send_data(@buffer,:filename => @containerformat.streamName,
    :disposition => 'attachment')
  pos=f.tell
  end

end

```

now am doing it like above and trying to download 284mb of file  
but only 211 bytes of file being downloaded..  
why??

---

<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:** [October 7, 2010, 11:39pm UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/18 "2010-10-07T23:39:55Z")

</div>

Luis L. wrote:

> please read about streaming data without loading all the file contents.
> 
> You will need to either use rack directly or create a mongrel handler  
> to serve these files outside rails.
> 
> Rails can only deliver one full request meaning it will load the full  
> file before completing.

Notice that now you can use send\_file which is now (Rails 3) implemented  
through a rack middleware and includes X-sendfile headers.

---

<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:** [October 8, 2010, 7:01am UTC](https://www.ruby-forum.com/t/failed-to-allocate-memory-while-downloading-large-files/194900/19 "2010-10-08T07:01:51Z")

</div>

Daniel Cadenas wrote:

> Luis L. wrote:
> 
> > please read about streaming data without loading all the file contents.
> > 
> > You will need to either use rack directly or create a mongrel handler  
> > to serve these files outside rails.
> > 
> > Rails can only deliver one full request meaning it will load the full  
> > file before completing.
> 
> Notice that now you can use send\_file which is now (Rails 3) implemented  
> through a rack middleware and includes X-sendfile headers.

yaa Daniel i already imlemented send\_file method and now i downloaded 7  
gb of file without fail ..  
The only problem am facing is how do i delete  
mongrel temporary after upload large files..
