I always got scared when my client ask for upload functionality. Basically from what I’ve read that when user uploaded a file it will an instance of the web server. So if i have one dyno (instance) on heroku, while one user is uploading a big file then the application would not respond to another user request until the file is done ?
I also find a couple of solution like carrierwave-direct which the file is uploaded directly to the storage server (let say S3), then rails can latter process the file. If we are to build like a social networking which involves many user uploading file in the same time, what is the correct approach to the problem?
Ahmy Y
I always got scared when my client ask for upload functionality. Basically
from what I've read that when user uploaded a file it will an instance of
the web server. So if i have one dyno (instance) on heroku, while one user
is uploading a big file then the application would not respond to another
user request until the file is done ?
Exactly when the file upload gets handed over to rails will depend on
your precise setup. On a standard apache/passenger type setup the
request only gets passed into rails when the request has been fully
received. I've not used heroku for this sort of stuff - it should be
say enough to determine what exactly happens.
I also find a couple of solution like carrierwave-direct which the file is
uploaded directly to the storage server (let say S3), then rails can latter
process the file. If we are to build like a social networking which
involves many user uploading file in the same time, what is the correct
approach to the problem?
S3 does indeed support pre-authenticated uploads. I'd certainly
investigate this, since with heroku you're going to have to upload the
file to s3 (or similar) at some point anyway, seems like you might as
well send it straight there.
Fred
One solution is to use transloadit.com and bypass the server entirely.
I got this from the heroku documentation
Pass-through uploads
Pass-through uploading sends the file from the user to the application on Heroku which then uploads it to S3.
Benefits of this approach include the ability to pre-process user-uploads before storing in S3. However, be careful that large files don’t tie up your application dynos during the upload process.
Large files uploads in single-threaded, non-evented environments (such as Rails) block your application’s web dynos and can cause request timeouts and H11, H12 errors. EventMachine, Node.js and JVM-based languages are less susceptible to such issues. Please be aware of this constraint and choose the right approach for your language or framework.
I think that i uses thin underneath the rails application. So does that mean, rails is not suited for file upload ?
Ahmy Yulrizka