Created
July 10, 2013 22:51
-
-
Save adamloving/5970906 to your computer and use it in GitHub Desktop.
Throw-away sample code for uploading files to Rackspace CDN
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
# docs here: | |
# https://github.com/nodejitsu/pkgcloud/blob/master/docs/providers/rackspace/storage.md | |
_ = require('underscore') | |
walk = require('walk') | |
pkgcloud = require('pkgcloud') | |
getClient = -> | |
pkgcloud.storage.createClient | |
provider: 'rackspace' | |
username: process.env.RACKSPACE_USERNAME | |
apiKey: process.env.RACKSPACE_API_KEY | |
authUrl: 'https://auth.api.rackspacecloud.com' | |
region: 'ORD' | |
uploadOne = (filePath, remoteFilePath) -> | |
console.log "Uploading", remoteFilePath | |
getClient().upload | |
container: tempContainerName | |
remote: remoteFilePath | |
local: filePath | |
, | |
(err, result) -> | |
if result then console.log "Succeded", remoteFilePath | |
else console.log "Fail", err | |
filePaths = [] | |
walker = walk.walk(contentPath, followLinks: false) | |
walker.on 'file', (root, stat, next) -> | |
filePaths.push(root + '/' + stat.name) | |
next() | |
walker.on 'end', -> | |
console.log "Creating #{tempContainerName} container..." | |
getClient().createContainer name: tempContainerName, (err, container) -> | |
console.log "Created container", err, container.name | |
for filePath in filePaths[0..10] | |
remoteFilePath = filePath.replace("#{contentPath}/", '') | |
_.partial(uploadOne, filePath, remoteFilePath)() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment