diff options
author | Ádám Hóka | 2018-05-31 13:15:41 +0200 |
---|---|---|
committer | Adam Hoka | 2018-06-01 10:07:52 +0200 |
commit | 376fcab2ca8a2908187bedec732fc99e1f1950c0 (patch) | |
tree | e5244e468e0a3e5ae7bcbccb3051d79c3ab4f045 /lib/web | |
parent | 12ab90020abc8a91f9eb9348ce2748ffa1d29365 (diff) |
Add Azure Blob Storage support
Signed-off-by: Adam Hoka <hoka.adam@nexogen.hu>
Diffstat (limited to 'lib/web')
-rw-r--r-- | lib/web/imageRouter/azure.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/web/imageRouter/azure.js b/lib/web/imageRouter/azure.js new file mode 100644 index 00000000..cc98e5fc --- /dev/null +++ b/lib/web/imageRouter/azure.js @@ -0,0 +1,35 @@ +'use strict' +const path = require('path') + +const config = require('../../config') +const logger = require('../../logger') + +const azure = require('azure-storage') + +exports.uploadImage = function (imagePath, callback) { + if (!imagePath || typeof imagePath !== 'string') { + callback(new Error('Image path is missing or wrong'), null) + return + } + + if (!callback || typeof callback !== 'function') { + logger.error('Callback has to be a function') + return + } + + var azureBlobService = azure.createBlobService(config.azure.connectionString) + + azureBlobService.createContainerIfNotExists(config.azure.container, { publicAccessLevel: 'blob' }, function (err, result, response) { + if (err) { + callback(new Error(err.message), null) + } else { + azureBlobService.createBlockBlobFromLocalFile(config.azure.container, path.basename(imagePath), imagePath, function (err, result, response) { + if (err) { + callback(new Error(err.message), null) + } else { + callback(null, azureBlobService.getUrl(config.azure.container, result.name)) + } + }) + } + }) +} |