forked from leopardslab/clocal-azure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage-example.js
executable file
·94 lines (80 loc) · 2.32 KB
/
storage-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const azure = require('azure-storage');
const accountKey = 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==';
const accountName = 'devstoreaccount1';
let devStoreCreds = azure.generateDevelopmentStorageCredentials();
const blobService = azure.createBlobService(devStoreCreds);
const tableService = azure.createTableService(devStoreCreds);
const queueService = azure.createQueueService(devStoreCreds);
/*
Use to debug the results
blobService.logger.level = azure.Logger.LogLevels.DEBUG
tableService.logger.level = azure.Logger.LogLevels.DEBUG
queueService.logger.level = azure.Logger.LogLevels.DEBUG
*/
const container = 'taskcontainer';
const task = 'taskblob';
const filename = 'data.txt';
let proxyBlob = {
protocol: 'http:',
host: '127.0.0.1',
port: 9569,
};
blobService.setProxy(proxyBlob);
let proxyQueue = {
protocol: 'http:',
host: '127.0.0.1',
port: 9570
};
queueService.setProxy(proxyQueue);
let proxyTbl = {
protocol: 'http:',
host: '127.0.0.1',
port: 9571,
};
tableService.setProxy(proxyTbl);
blobService.createContainerIfNotExists(container, error => {
if (error) return console.log(error);
blobService.createBlockBlobFromLocalFile(
container,
task,
filename,
(error, result) => {
if (error) return console.log(error);
console.dir(result, { depth: null, colors: true });
}
);
});
// Create queue
queueService.createQueueIfNotExists('myqueue', "Hello world!", function(error, results, response){
if(!error){
// Queue created or exists
console.log("Queue result: "+ results.created);
console.log(results);
} else {
console.log(error)
}
});
tableService.createTable('tablesample', function(error, result, response) {
if (!error) {
// result contains true if created; false if already exists
console.dir("Table Result: "+result.isSuccessful)
} else {
console.log(error)
}
});
// // Remove queue
// queueService.deleteQueue('myqueue', function(error, response){
// if(!error){
// // Queue has been deleted
// console.log(response)
// }
// });
//Delete Table
// tableService.deleteTable('mytable', function(error, response){
// if(!error){
// // Table deleted
// console.log(response)
// } else {
// console.log(error)
// }
// });