# Rails threaded file upload via cURL

**URL:** <https://www.ruby-forum.com/t/rails-threaded-file-upload-via-curl/141235>\
**Category:** Ruby\
**Created:** [June 23, 2008, 10:30pm UTC](https://www.ruby-forum.com/t/rails-threaded-file-upload-via-curl/141235 "2008-06-23T22:30:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dezrtdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@dezrtdude](https://www.ruby-forum.com/u/dezrtdude)\
**Post date:** [June 23, 2008, 10:30pm UTC](https://www.ruby-forum.com/t/rails-threaded-file-upload-via-curl/141235/1 "2008-06-23T22:30:46Z")

</div>

Hi All,

I am currently working on a project that needs to upload multiple  
files to a server. It needs to do so in quick fashion. Originally I  
had a script that simply uploaded files serially and it worked like a  
charm. My client, however, requires it to work “somewhat faster, and  
upload more at a time”. So, I added threading. The problem is, that  
the application is supposed to repeat and always upload whenever files  
are present. As such I have it inside a “while” loop.

The problem I’m having is that with Threading, the final cURL  
transaction seems to linger eternally and the process will never  
repeat. However, if I go back to serial processing, everything works  
fine. What aspect of threading am I not taking into account?

The semi-demi-gist of the code is as follows:

while 1  
my\_threads = []

list\_of\_files = function\_fill\_file\_list()

list\_of\_files.each {|cur\_file|  
my\_threads \<\< Thread.new {

```
  command = "curl -F filedata=#{file} http://10.0.0.1/awesome.php"
  system(command)
  deletefile(cur_file)

}

```

}

my\_threads.each { |cur\_thread| cur\_thread.join}

sleep(10)

end

Best Regards.
