Skip to content

Instantly share code, notes, and snippets.

@samsm
Created April 18, 2011 15:41
Show Gist options
  • Save samsm/925575 to your computer and use it in GitHub Desktop.
Save samsm/925575 to your computer and use it in GitHub Desktop.
A quick way to try out assemblies with Transloadit without any backend support.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Transloadit</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://assets.transloadit.com/js/jquery.transloadit2.js"></script>
<script type="text/javascript">
function htmlEntities(str) {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
// We call .transloadit() after the DOM is initialized:
$(document).ready(function() {
var params = {
"auth": {
"key": "*****************"
},
"template_id" : "*****************",
'redirect_url' : 'http://example.org/upload',
'steps' : {
"resize_to_75": {
"robot": "/image/resize",
"width": 75,
"height": 75,
"use": ':original'
},
'export' : {
'use' : [':original', 'resize_to_75']
}
}
};
var encoded_params = htmlEntities(JSON.stringify(params));
$('#MyForm').prepend('<input type="hidden" name="params" value="'+encoded_params+'" />').transloadit({
wait: true,
autoSubmit: false,
onSuccess: function(assembly) {
$.foo = assembly;
jQuery.each(assembly.results, function(index,result) {
file = result[0];
$.res = result;
$.ind = index;
var div = $('<div id="'+file['id']+'">');
div.append('<a href="'+file['url']+'">'+file['name']+'</a> ('+index+')<br />');
if (file['mime'].match(/^image/)) {
div.append('<img src="'+file['url']+'" />');
}
$('#results').append(div)
});
$('#MyForm')[0].reset();
}
});
});
</script>
</head>
<body>
<form id="MyForm" action="http://api2.transloadit.com/assemblies" enctype="multipart/form-data" method="post" name="MyForm">
<input type="file" name="my_file" />
<input type="submit" value="Upload" />
</form>
<div id="results"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment