Skip to content

Instantly share code, notes, and snippets.

@artursapek
Created July 3, 2012 20:32
Show Gist options
  • Select an option

  • Save artursapek/3042867 to your computer and use it in GitHub Desktop.

Select an option

Save artursapek/3042867 to your computer and use it in GitHub Desktop.
CM Uploads
// Download a file to your machine
download = function(key){
// The CM download API call only requires a key as a parameter.
// Here we also include a second options parameter where "filename" tells
// the SDK we want to download the file to our local filesystem.
cm.download(key, {filename: key});
}
downloadBinary = function(key){
// Add a "mode" option to get the file as an ArrayBuffer
cm.download(key, {mode: 'buffer'})
.on('success', function(response){
var arrayBuffer = response[key]
});
}
downloadBinary = function(key){
cm.download(key)
.on('success', function(response){
var binaryData = response[key]
});
}
cm.upload(fileName, file);
cm.download(fileName);
upload = function(){
// Get the file selected
var file = $('#upload')[0].files[0];
// Set the click handler on the Upload button
$('button.upload').click(function(){
// Make the CM upload API call. Parameters: reference key, file object
cm.upload(file.name, file);
});
// Return the file data
return file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment