# Photo uploads and scalability

**URL:** <https://www.ruby-forum.com/t/photo-uploads-and-scalability/222532>\
**Category:** NGINX\
**Created:** [August 31, 2012, 7:40pm UTC](https://www.ruby-forum.com/t/photo-uploads-and-scalability/222532 "2012-08-31T19:40:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 31, 2012, 7:40pm UTC](https://www.ruby-forum.com/t/photo-uploads-and-scalability/222532/1 "2012-08-31T19:40:50Z")

</div>

Getting ready to work on a new section of the site which will require a  
reader to upload a photo and write a caption.

It’s my first time writing anything to do with uploading and I’m  
wondering what things in the nginx realm I need to consider so the  
system doesn’t get bogged down. Nginx is a dream for us serving files,  
but since I’ve never handled uploads, what pitfalls/traps/surprises do I  
need to be prepared for?

I’d like to think of scalability from day one so I’m not trying to fix  
something under load. Right now I have one server. Is there anyway to  
prepare my nginx.conf for easily handling, say, new servers getting  
added/removed in the cloud?

[Hey, we might get 1 upload a week or a million a day, so it’s good to  
be prepared.]

From a programming end I already know I’ll queue any post-processing  
and inform the reader when it’s done so that process can be handled by  
my local server or cloud instances etc.

Thanks for any tips!

---

<div class="post-metadata">

**Author:** ![peterpiper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3e96dc/32.png) [@peterpiper](https://www.ruby-forum.com/u/peterpiper)\
**Post date:** [August 31, 2012, 8:01pm UTC](https://www.ruby-forum.com/t/photo-uploads-and-scalability/222532/2 "2012-08-31T20:01:52Z")

</div>

On Friday 31 August 2012 21:40:16 Ian E. wrote:  
[…]

> From a programming end I already know I’ll queue any post-processing  
> and inform the reader when it’s done so that process can be handled by  
> my local server or cloud instances etc.

TIP: You can avoid passing files over an upstream connection.

Example:

location = /upload {  
proxy\_pass [http://backend](http://backend);  
client\_body\_in\_file\_only clean;  
proxy\_set\_body $request\_body\_file;  
}

Your application should “mv” uploaded file somewhere, then register a  
task  
for further background processing, and return a response.

Reference: [Module ngx\_http\_core\_module](http://nginx.org/r/client_body_in_file_only)

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![peterpiper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3e96dc/32.png) [@peterpiper](https://www.ruby-forum.com/u/peterpiper)\
**Post date:** [September 1, 2012, 7:18am UTC](https://www.ruby-forum.com/t/photo-uploads-and-scalability/222532/3 "2012-09-01T07:18:28Z")

</div>

On 31/08/2012 2:01 PM, Valentin V. Bartenev wrote:

> location = /upload {  
> proxy\_pass [http://backend](http://backend);  
> client\_body\_in\_file\_only clean;  
> proxy\_set\_body $request\_body\_file;  
> }
> 
> Your application should “mv” uploaded file somewhere, then register a task  
> for further background processing, and return a response.

As photos are several megabytes, should I be looking into nginx’s upload  
module?

---

<div class="post-metadata">

**Author:** ![peterpiper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3e96dc/32.png) [@peterpiper](https://www.ruby-forum.com/u/peterpiper)\
**Post date:** [September 1, 2012, 9:07am UTC](https://www.ruby-forum.com/t/photo-uploads-and-scalability/222532/4 "2012-09-01T09:07:06Z")

</div>

upload\_module removes uploaded files from body and replaces them with  
paths to temporary files where there are stored at end.

So your backend don’t have to parse body again to extract files from  
it. Parsing costs memory & cpu.

If you upload photos, they will land on disk. Your backend can analyze  
them briefly, make first thumb to be shown back to user and ask/  
schedule other workers to make scalling/rotating and any image  
processing you want to be done later in real background.

I’m happy user of upload\_module 😉  
in tandem with uploadprogress\_module

It is easy to setup, very.

imho: it’s worthwhile

Regards  
Pawe Marzec

Wiadomo napisana w dniu 2012-09-01, o godz. 07:17, przez Ian E.:

---

<div class="post-metadata">

**Author:** ![peterpiper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3e96dc/32.png) [@peterpiper](https://www.ruby-forum.com/u/peterpiper)\
**Post date:** [September 1, 2012, 10:42am UTC](https://www.ruby-forum.com/t/photo-uploads-and-scalability/222532/5 "2012-09-01T10:42:56Z")

</div>

On 01/09/2012 3:06 AM, “Pawe Marzec - cojestgrane.pl” wrote:

> I’m happy user of upload\_module 😉  
> in tandem with uploadprogress\_module
> 
> It is easy to setup, very.
> 
> imho: it’s worthwhile

Is there an article or tutorial that show examples of how to set the  
module up? I’ve been looking around and see that some people are using  
it with the a plugin called plupload. Any experience with that?

---

<div class="post-metadata">

**Author:** ![peterpiper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3e96dc/32.png) [@peterpiper](https://www.ruby-forum.com/u/peterpiper)\
**Post date:** [September 1, 2012, 11:12am UTC](https://www.ruby-forum.com/t/photo-uploads-and-scalability/222532/6 "2012-09-01T11:12:44Z")

</div>

try this:

> **[Uploading multiple files with nginx upload module and upload progress bar](https://blog.joshsoftware.com/2010/10/20/uploading-multiple-files-with-nginx-upload-module-and-upload-progress-bar/)**
>
> Uploading files ‘efficiently’ has also been a pain point in most apps. I finally got to experiment with: nginx upload module ( nginx upload progress module and upload multiple files via…

Pawe Marzec

Wiadomo napisana w dniu 2012-09-01, o godz. 10:42, przez Ian E.:

---

<div class="post-metadata">

**Author:** ![peterpiper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3e96dc/32.png) [@peterpiper](https://www.ruby-forum.com/u/peterpiper)\
**Post date:** [September 2, 2012, 1:22am UTC](https://www.ruby-forum.com/t/photo-uploads-and-scalability/222532/7 "2012-09-02T01:22:26Z")

</div>

On 01/09/2012 5:12 AM, “Pawe Marzec - cojestgrane.pl” wrote:

> try this:

> **[Uploading multiple files with nginx upload module and upload progress bar](https://blog.joshsoftware.com/2010/10/20/uploading-multiple-files-with-nginx-upload-module-and-upload-progress-bar/)**
>
> Uploading files ‘efficiently’ has also been a pain point in most apps. I finally got to experiment with: nginx upload module ( nginx upload progress module and upload multiple files via…

Thanks. Does anyone know of an example integrating it with PHP? I’m  
seeing examples for Passenger and Rails, but I don’t use them.

Thanks for the help. Just want to make sure I can scale from day one.
