Created
July 3, 2012 20:32
-
-
Save artursapek/3042867 to your computer and use it in GitHub Desktop.
CM Uploads
This file contains hidden or 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
| // 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}); | |
| } |
This file contains hidden or 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
| 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] | |
| }); | |
| } |
This file contains hidden or 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
| downloadBinary = function(key){ | |
| cm.download(key) | |
| .on('success', function(response){ | |
| var binaryData = response[key] | |
| }); | |
| } |
This file contains hidden or 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
| cm.upload(fileName, file); | |
| cm.download(fileName); |
This file contains hidden or 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
| 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