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

89 lines
2.0 KiB
JavaScript
Raw Normal View History

2014-01-24 17:32:48 +00:00
var StorageService = require('../').StorageService;
var path = require('path');
var rs = StorageService({
2014-01-24 17:44:58 +00:00
provider: 'rackspace',
username: 'strongloop',
apiKey: 'your-rackspace-api-key'
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',
key: 'your-amazon-key',
keyId: 'your-amazon-key-id'
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
});