loopback-component-storage/example/app-cloud.js

90 lines
2.1 KiB
JavaScript
Raw Normal View History

2014-01-24 17:32:48 +00:00
var StorageService = require('../').StorageService;
var path = require('path');
2014-01-24 18:19:03 +00:00
var providers = require('./providers.json');
2014-01-24 17:32:48 +00:00
var rs = StorageService({
2014-01-24 17:44:58 +00:00
provider: 'rackspace',
2014-01-24 18:19:03 +00:00
username: providers.rackspace.username,
apiKey: providers.rackspace.apiKey
2014-01-24 17:32:48 +00:00
});
// Container
rs.getContainers(function (err, containers) {
2014-01-24 17:44:58 +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);
});
2014-01-24 17:32:48 +00:00
});
2014-01-24 17:44:58 +00:00
});
2014-01-24 17:32:48 +00:00
});
/*
client.createContainer(options, function (err, container) { });
client.destroyContainer(containerName, function (err) { });
client.getContainer(containerName, function (err, container) { });
// 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({
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
});
s3.getContainers(function (err, containers) {
2014-01-24 17:44:58 +00:00
if (err) {
console.error(err);
return;
}
containers.forEach(function (c) {
console.log('amazon: ', c.name);
c.getFiles(function (err, files) {
files.forEach(function (f) {
console.log('....', f.name);
});
2014-01-24 17:32:48 +00:00
});
2014-01-24 17:44:58 +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-01-24 17:32:48 +00:00
var input = fs.createReadStream(path.join(__dirname, 'test.jpg')).pipe(stream);
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
});
// Container
local.getContainers(function (err, containers) {
2014-01-24 17:44:58 +00:00
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);
});
2014-01-24 17:32:48 +00:00
});
2014-01-24 17:44:58 +00:00
});
2014-01-24 17:32:48 +00:00
});