I am using carrierwave to upload Video files and encoding that videos using Transloadit. What is the best way to do this in rails with delayed job. please suggest.
2 Answers
There are a number of options (purely the HTTP side of things, not even talking about programming languages).
The question is really depending on your environment(s), skills, support etc. What I've noticed in the 'real world' is that if you send >100MB to a server over an HTTP request, it will fail. Your clients most likely have really bad upload speeds (most soho internet connections are >10M down but <1M up) so you'll eventually hit a timeout (router/nat tables/firewall/web server/scripts).
1) Really large POST (bad practice, could potentially consume a lot of memory, failure means you have to start all over and leaves your server open to DDoS)
2) Using an 'upload module' for Apache/nginx (requires compilation and generally a lot of headache to get it set up but it works well, may not work with all hosting situations)
3) Streaming within your client and server scripts. Works well. I would also recommend chunking your uploads to <10MB and when they fail, the possibility of restarting chunks.

- 184
- 5
I'm not much experienced with DJ, but backgroud processing have similar approach with all tools.
First you should just upload your file somewhere(filesystem, Amazon S3, whatever). DJ will not handle this task. You should do it at your controller action.
Then, after upload you can create DJ task, that encodes your video and does other related tasks.
For example, you can run DJ after commit in your video model, like
class Video < AR::Base
after_commit :encode_in_background
private
def encode_in_background
self.delay.encode(id)
end
def encode
# code that runs in background
end
end
My example can have incorrect syntax, but the main idea is that you upload video via controller and then run background processing job.

- 4,276
- 2
- 20
- 25
-
yes you are correct. But if i upload 2 GB file ,my local machine hangs, and it couldn't complete the request – user2886647 Mar 30 '15 at 17:28
-
Well, uploading 2 GB on local machine is a really heavy task. Then try some nginx upload method. But anyway, if you need to upload such huge files, than your service is quite specific, and you should have a powerful servers for handling such tasks(with a lot of RAM and disk space) – Stanislav Mekhonoshin Mar 30 '15 at 17:35
-
>2GB might be more than your webserver allows for a post request see Apache: http://httpd.apache.org/docs/2.4/mod/core.html#limitrequestbody – tvw Jul 19 '16 at 07:53