Created
April 18, 2011 15:41
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); | |
} | |
// 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