mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 22:54:42 -04:00
Add Azure Blob Storage support
Signed-off-by: Adam Hoka <hoka.adam@nexogen.hu>
This commit is contained in:
parent
12ab90020a
commit
376fcab2ca
8 changed files with 60 additions and 6 deletions
35
lib/web/imageRouter/azure.js
Normal file
35
lib/web/imageRouter/azure.js
Normal file
|
@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue