Transloadit is a file-processing service primarily designed for processing images, videos and audio.
It allows you to perform various operations — conducted by what it calls “robots” — on these files; for example resizing and optimizing images, extracting thumbnails from videos or converting files from one format to another.
TransloadIt also allows you to upload files directly to their servers for processing rather than via your application. Indeed you can bypass your server altogether, transferring the processed files straight to an Amazon S3 bucket, a Rackspace Cloud Files account or to your own server via (S)FTP. So in other words, your application need only be concerned with where to find the resulting files, without having to process or store them directly — great for running distributed applications or for those on clusters.
In this tutorial we’re going to take a detailed look at Transloadit, and in particular using it to handle images. We’ll look at some of the key concepts, such as constructing “assembly instructions” to tell it what we want to happen to our uploaded image files. We’ll “hijack” a file upload form to send a file directly to TransloadIt, run a set of instructions to generate a number of “derivatives” — different-sized images — and then save them to an Amazon S3 bucket. Finally, we’ll look at how we can use the results of these operations to notify our application about the newly generated files, so that we can update our database accordingly.
Before we look in detail at Transloadit, it’s worth taking a step back and discussing why you’d want to use a third-party service for something like this in the first place, rather than implement it all yourself.
Why Use a Third-party Service?
Image handling isn’t all that difficult to implement yourself, and there are all sorts of libraries out there for just that. So why would you want to use a third-party service to handle it at all?
-
For one thing, it allows you to concentrate on what your application is really all about. Why spend additional time and effort on, say, user profile photo functionality when you could be concentrating your development efforts on mission-critical functionality?
-
Image processing can be quite resource intensive. In particular, resizing large images can eat up a lot of memory. Using a service such as Transloadit eases the load on your servers.
-
Processing files usually requires additional libraries or programs to be installed on your server; for example
gd
orImagemagick
for images orffmpeg
for videos and audio. By using a third-party service, there’s no need to worry about installing, configuring or maintaining them. -
Transloadit “jobs” can be run in the background, rather than hold up execution of your application. While there are solutions to get around this in your own application — for example queues such as RabbitMQ or Beanstalkd, or job servers such as Gearman, using TransloadIt frees you from the additional development effort and installation steps required to implement them.
-
The Transloadit servers are highly optimized to handle file uploads, so performance may well be much better than if you implement them yourself.
-
Permitting files to be uploaded to your web server also has all sorts of security implications which you must take into consideration. By using a third-party service, these risks are somewhat mitigated.
-
It’s decentralized. You can set it up such that uploaded files go via the service and straight to an external storage solution such as S3, without ever having to be stored on your web server. Whilst this might not seem a huge advantage in a small-scale application, you’ll reap the benefits as soon as it grows to the point where you have multiple services, for example a cluster.
Depending on your application, your preferred hosting solution, your expertise or the amount of time you happen to have on your hands, chances are not all of these will apply. Perhaps none; it’s not the optimum solution for all cases.
Naturally, there are disadvantages. Here are a few:
- It introduces an additional point-of-failure.
- It could mean entrusting sensitive files to a third-party.
- Finally, there’s the financial cost.
Bearing all of those pros and cons in mind, let’s start taking a detailed look at the service. Then, in part two, we’ll run through a practical example of how to use it.
Continue reading %Getting Started with TransloadIt – Key Concepts%
by Lukas White via SitePoint
No comments:
Post a Comment