loopback-component-storage/example/app.js

84 lines
2.0 KiB
JavaScript
Raw Normal View History

var StorageService = require('../');
2013-06-25 20:06:54 +00:00
var path = require('path');
2013-06-24 21:07:12 +00:00
var rs = StorageService({
2013-06-24 21:07:12 +00:00
provider: 'rackspace',
2013-06-25 16:29:53 +00:00
username: 'strongloop',
apiKey: 'your-rackspace-api-key'
});
2013-06-24 21:07:12 +00:00
// Container
2013-06-25 20:06:54 +00:00
rs.getContainers(function (err, containers) {
2013-06-25 17:55:28 +00:00
if (err) {
console.error(err);
return;
}
containers.forEach(function (c) {
console.log('rackspace: ', c.name);
c.getFiles(function (err, files) {
files.forEach(function (f) {
console.log('....', f.name);
});
});
2013-06-25 16:29:53 +00:00
});
});
2013-06-24 21:07:12 +00:00
2013-06-25 16:29:53 +00:00
/*
client.createContainer(options, function (err, container) { });
client.destroyContainer(containerName, function (err) { });
client.getContainer(containerName, function (err, container) { });
2013-06-24 21:07:12 +00:00
2013-06-25 16:29:53 +00:00
// File
client.upload(options, function (err) { });
client.download(options, function (err) { });
client.getFiles(container, function (err, files) { });
client.getFile(container, file, function (err, server) { });
client.removeFile(container, file, function (err) { });
*/
var s3 = StorageService({
2013-06-25 16:29:53 +00:00
provider: 'amazon',
key: 'your-amazon-key',
keyId: 'your-amazon-key-id'
});
s3.getContainers(function (err, containers) {
2013-06-25 17:55:28 +00:00
if (err) {
2013-06-25 16:29:53 +00:00
console.error(err);
return;
}
2013-06-25 17:55:28 +00:00
containers.forEach(function (c) {
console.log('amazon: ', c.name);
c.getFiles(function (err, files) {
files.forEach(function (f) {
console.log('....', f.name);
});
});
2013-06-25 16:29:53 +00:00
});
});
2013-06-25 20:06:54 +00:00
var fs = StorageService({
2013-06-25 20:06:54 +00:00
provider: 'filesystem',
root: path.join(__dirname, 'storage')
});
// Container
fs.getContainers(function (err, containers) {
if (err) {
console.error(err);
return;
}
containers.forEach(function (c) {
console.log('filesystem: ', c.name);
c.getFiles(function (err, files) {
files.forEach(function (f) {
console.log('....', f.name);
});
});
});
});