Processing multiple file types

Archived from the Transloadit support forum. Originally posted on January 14, 2011; details may be outdated, see our docs for current behavior. Original thread

I’d like to create an upload form that allows a user to upload any file type, and then use your service to process it based on filetype. So, for example, if an image file is uploaded - I’d like to thumbnail and store it, if it’s a video file - encode, thumb, store. If it’s a word document or spreadsheet - just store it.

Is it possible to have a single upload form that has this processing type logic based on filetype. I’ve looked at your Assemblies docs, but can’t quite see if something like this is possible.

Thanks.

Yes, this is possible. All Transloadit robots will simply ignore files that they can’t handle. So you just need to setup 2 steps that have "use": ":original" with different robots, and the files will be automatically routed to them based on the file type.

Let me know if this makes sense or if I should explain further.

We are currently re-working the docs to be more helpful with questions like this!

That sounds great. Could you provide an example of an assembly that can do this? I haven’t been able to do this yet. Basically, I’d like to do this:

If Image file is uploaded - I’d like to thumbnail and store it
If it’s a video file - encode, thumb, and store it
If it’s a word document or spreadsheet - just store it

The service looks great. I hope I can get this to work.

Hey Jim,

here is such a set of assembly instructions:

{ steps

"image_resize":{
  "use":":original",
  "robot":"/image/resize",
  "width":640,
  "height":480
},
"encode_video":{
  "use":":original",
  "robot":"/video/encode",
  "preset":"flash",
  "width":640,
  "height":480
},
"store":{
  "use":["image_resize", "encode_video", ":original"],
  "robot":"/s3/store",
  "key":"YOUR_AWS_KEY",
  "secret":"YOUR_AWS_SECRET",
  "bucket":"YOUR_S3_BUCKET"
}

} }

Notice how both the image resize and the video encode step have “:original” as their use parameter. That tells them to use the originally uploaded file(s) for their operation. The image resize robot will ignore files that are not an image. The video/encode robot ignores non-videos.

The store robot then stores the results of the two steps and the originally uploaded file in S3.

By the way, as Felix said, we are currently reworking our documentation to reflect such stuff better. Would you like us to show you the current stage of the updated documentation so you can review it? We’d love to work closely with our customers to get our documentation right. And since you are still in the middle of integrating Transloadit first-time, you are the perfect customer to do this with.

Let me know if you are interested.

Kind regards,
Tim

Thanks - that helped. I was able to get all file types to work with this. Basically, this template will do the following:

for images - create a thumb, and store thumb, store orig image file for pdfs - create a thumb, and store thumb, store orig pdf
for videos - create 4 thumbs, encode video to flv, store thumbs and store orig video

{ "steps":
  { "image_thumbs":
    { "use": ":original"
    , "robot": "/image/resize"
    , "format": "png"
    , "width": 320
    , "height": 240
    }
, "video_thumbs":
    { "use": ":original"
    , "robot": "/video/thumbs"
    , "width": 320
    , "height": 240
    , "resize_strategy": "pad"
    , "background": "#000000"
    , "count": 4
    }
, "encode_video":
    { "use": ":original"
    , "robot": "/video/encode"
    , "preset": "flash"
    , "width": 640
    , "height": 480
    }
, "store":
    { "use": ["image_thumbs", "video_thumbs", "encode_video", ":original"]
    , "robot": "/s3/store"
    , "bucket": "YOUR_S3_BUCKET"    
    , "key": "YOUR_AWS_KEY"
    , "secret": "YOUR_AWS_SECRET"
    }
  }
}

Regarding docs. If you just added this example “How to process multiple file types” to your demos page - that would be great.