Skip to content

Instantly share code, notes, and snippets.

@davidwood
Created December 9, 2011 19:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwood/1453050 to your computer and use it in GitHub Desktop.
Save davidwood/1453050 to your computer and use it in GitHub Desktop.
List content type of files in Cloudfiles container
var cloudfiles = require('cloudfiles');
// CloudFiles client configuration
var configCloudFiles = {
auth: {
username: 'USERNAME',
apiKey: 'API_KEY',
host: 'auth.api.rackspacecloud.com'
}
};
// Get the container argument
var containerName = '';
if (process.argv.length > 2) containerName = process.argv[2];
if (containerName == '') return console.error('Invalid container');
// Create the client and auth
var client = cloudfiles.createClient(configCloudFiles);
client.setAuth(function() {
// Get the container
client.getContainer(containerName, function (err, container) {
if (err) return console.error(err);
// Get all the files in the container
container.getFiles(function (err, files) {
if (err) return console.error(err);
files.forEach(function(file) {
console.log(file.name + ' - ' + file.contentType);
});
});
});
});

How to list the content type of all files in a Cloudfiles container.

  1. Install node and npm
  2. Install the awesome Cloudfiles package from Nodejitsu
  3. Create a folder and save the dw-is-my-hero.js to that folder
  4. Edit dw-is-my-hero.js and change USERNAME and API_KEY to your username and API key
  5. Run node dw-is-my-hero.js CONTAINER_NAME
  6. Smile (and tell people how rad node.js is)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment