Skip to content

Instantly share code, notes, and snippets.

@anhphamt
Last active June 5, 2017 09:39
Show Gist options
  • Save anhphamt/245e04f07d00a6c232527118b932b4eb to your computer and use it in GitHub Desktop.
Save anhphamt/245e04f07d00a6c232527118b932b4eb to your computer and use it in GitHub Desktop.
OpenStack Authen V3 pkgCloud
https://developer.ibm.com/recipes/tutorials/use-pkgcloud-to-access-ibm-object-storage-for-bluemix-with-node-js/
var pkgcloud = require('pkgcloud');
var config = {
provider: 'openstack',
useServiceCatalog: true,
useInternal: false,
keystoneAuthVersion: 'v3',
authUrl: 'https://identity.open.softlayer.com',
tenantId: 'ae89fb461f8345d397c720fe7f53aa42', //projectId from credentials
domainId: 'db873a6fd7e049fe9bc635f9e96541b4',
username: 'admin_516cc850466569787ad1d9acc53c3f4ef63ac258',
password: 'xxxxxxxxxxxx',
region: 'dallas' //dallas or london region
};
var storageClient = pkgcloud.storage.createClient(config);
storageClient.auth(function(err) {
if (err) {
console.error(err);
}
else {
console.log(storageClient._identity);
}
});
var fs = require('fs');
storageClient.createContainer({
name: 'my-container'
}, function (err, container) {
if (err) {
console.error(err);
}
else {
var myFile = fs.createReadStream('/path/to/some/file.txt');
var upload = storageClient.upload({
container: container.name,
remote: 'file.txt'
});
upload.on('error', function(err) {
console.error(err);
});
upload.on('success', function(file) {
console.log(file.toJSON());
});
myFile.pipe(upload);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment