2014-01-24 17:32:48 +00:00
|
|
|
var StorageService = require('../').StorageService;
|
|
|
|
var path = require('path');
|
2014-03-31 23:30:35 +00:00
|
|
|
var providers = null;
|
|
|
|
try {
|
|
|
|
providers = require('./providers-private.json');
|
|
|
|
} catch(err) {
|
|
|
|
providers = require('./providers.json');
|
|
|
|
}
|
2014-01-24 17:32:48 +00:00
|
|
|
|
2014-04-01 00:33:32 +00:00
|
|
|
function listContainersAndFiles(ss) {
|
|
|
|
ss.getContainers(function (err, containers) {
|
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log('----------- %s (%d) ---------------', ss.provider, containers.length);
|
|
|
|
containers.forEach(function (c) {
|
|
|
|
console.log('[%s] %s/', ss.provider, c.name);
|
|
|
|
c.getFiles(function (err, files) {
|
|
|
|
files.forEach(function (f) {
|
|
|
|
console.log('[%s] ... %s', ss.provider, f.name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var rs = new StorageService({
|
2014-01-24 17:44:58 +00:00
|
|
|
provider: 'rackspace',
|
2014-01-24 18:19:03 +00:00
|
|
|
username: providers.rackspace.username,
|
2014-03-31 23:30:35 +00:00
|
|
|
apiKey: providers.rackspace.apiKey,
|
|
|
|
region: providers.rackspace.region
|
2014-01-24 17:32:48 +00:00
|
|
|
});
|
|
|
|
|
2014-04-01 00:33:32 +00:00
|
|
|
listContainersAndFiles(rs);
|
2014-01-24 17:32:48 +00:00
|
|
|
|
2014-04-01 00:33:32 +00:00
|
|
|
var s3 = new StorageService({
|
2014-01-24 17:44:58 +00:00
|
|
|
provider: 'amazon',
|
2014-01-24 18:19:03 +00:00
|
|
|
key: providers.amazon.key,
|
|
|
|
keyId: providers.amazon.keyId
|
2014-01-24 17:32:48 +00:00
|
|
|
});
|
|
|
|
|
2014-04-01 00:33:32 +00:00
|
|
|
listContainersAndFiles(s3);
|
2014-01-24 17:32:48 +00:00
|
|
|
|
2014-03-31 23:30:35 +00:00
|
|
|
|
2014-01-24 17:32:48 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
2014-01-24 17:44:58 +00:00
|
|
|
var stream = s3.uploadStream('con1', 'test.jpg');
|
2014-03-31 23:30:35 +00:00
|
|
|
fs.createReadStream(path.join(__dirname, 'test.jpg')).pipe(stream);
|
2014-01-24 17:32:48 +00:00
|
|
|
|
|
|
|
var local = StorageService({
|
2014-01-24 17:44:58 +00:00
|
|
|
provider: 'filesystem',
|
|
|
|
root: path.join(__dirname, 'storage')
|
2014-01-24 17:32:48 +00:00
|
|
|
});
|
|
|
|
|
2014-04-01 00:33:32 +00:00
|
|
|
listContainersAndFiles(local);
|
2014-01-24 17:32:48 +00:00
|
|
|
|