summaryrefslogtreecommitdiff
path: root/lib/web
diff options
context:
space:
mode:
authorChristoph (Sheogorath) Kern2018-06-01 12:35:20 +0200
committerGitHub2018-06-01 12:35:20 +0200
commit65544f9a18a2a418cd88d8fc9f8ee227bd4cf03c (patch)
tree229e8c05b308452a6741d5436038a213833c2104 /lib/web
parentef1097c58dd35a12dbde471c6f33186d72a3916b (diff)
parent376fcab2ca8a2908187bedec732fc99e1f1950c0 (diff)
Merge pull request #675 from ahoka/master
Add Azure Blob Storage support
Diffstat (limited to '')
-rw-r--r--lib/web/imageRouter/azure.js35
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))
+ }
+ })
+ }
+ })
+}