Last active
December 15, 2015 13:19
-
-
Save ChrisRisner/5266227 to your computer and use it in GitHub Desktop.
Blob Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var azure = require('azure'); | |
function del(id, user, request) { | |
var accountName = 'accountname'; | |
var accountKey = 'accountkey'; | |
var host = accountName + '.blob.core.windows.net'; | |
var blobService = azure.createBlobService(accountName, accountKey, host); | |
blobService.deleteBlob(request.parameters.containerName, | |
request.parameters.blobName, function (error) { | |
if (!error) { | |
request.respond(200); | |
} else { | |
request.respond(500); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var azure = require('azure'); | |
var qs = require('querystring'); | |
function insert(item, user, request) { | |
var accountName = 'accountname'; | |
var accountKey = 'accountkey'; | |
var host = accountName + '.blob.core.windows.net'; | |
var blobService = azure.createBlobService(accountName, accountKey, host); | |
var sharedAccessPolicy = { | |
AccessPolicy: { | |
Permissions: 'rw', //Read and Write permissions | |
Expiry: minutesFromNow(5) | |
} | |
}; | |
var sasUrl = blobService.generateSharedAccessSignature(request.parameters.containerName, | |
request.parameters.blobName, sharedAccessPolicy); | |
var sasQueryString = { 'sasUrl' : sasUrl.baseUrl + sasUrl.path + '?' + qs.stringify(sasUrl.queryString) }; | |
request.respond(200, sasQueryString); | |
} | |
function minutesFromNow(minutes) { | |
var date = new Date() | |
date.setMinutes(date.getMinutes() + minutes); | |
return date; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var azure = require('azure'); | |
function read(query, user, request) { | |
var accountName = 'accountname'; | |
var accountKey = 'accountkey'; | |
var host = accountName + '.blob.core.windows.net'; | |
var blobService = azure.createBlobService(accountName, accountKey, host); | |
blobService.listBlobs(request.parameters.container, function (error, blobs) { | |
if (error) { | |
request.respond(500, error); | |
} else { | |
request.respond(200, blobs) | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var azure = require('azure'); | |
function del(id, user, request) { | |
var accountName = 'accountname'; | |
var accountKey = 'accountkey'; | |
var host = accountName + '.blob.core.windows.net'; | |
var blobService = azure.createBlobService(accountName, accountKey, host); | |
blobService.deleteContainer(request.parameters.containerName, function (error) { | |
if (!error) { | |
request.respond(200); | |
} else { | |
request.respond(500); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var azure = require('azure'); | |
function insert(item, user, request) { | |
var accountName = 'accountname'; | |
var accountKey = 'accountkey'; | |
var host = accountName + '.blob.core.windows.net'; | |
var blobService = azure.createBlobService(accountName, accountKey, host); | |
if (request.parameters.isPublic == 1) { | |
blobService.createContainerIfNotExists(item.containerName | |
,{publicAccessLevel : 'blob'} | |
, function (error) { | |
if (!error) { | |
request.respond(200, item); | |
} else { | |
console.log(error); | |
request.respond(500); | |
} | |
}); | |
} else { | |
blobService.createContainerIfNotExists(item.containerName, function (error) { | |
if (!error) { | |
request.respond(200, item); | |
} else { | |
console.log(error); | |
request.respond(500); | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var azure = require('azure'); | |
function read(query, user, request) { | |
var accountName = 'accountname'; | |
var accountKey = 'accountkey'; | |
var host = accountName + '.blob.core.windows.net'; | |
var blobService = azure.createBlobService(accountName, accountKey, host); | |
blobService.listContainers(function (error, containers) { | |
if (error) { | |
request.respond(500, error); | |
} else { | |
request.respond(200, containers); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment