Skip to content

Instantly share code, notes, and snippets.

@istumpf
Created February 9, 2018 10:43
Show Gist options
  • Select an option

  • Save istumpf/b2477b58bfdb5f24607e6bcdd1cc94fa to your computer and use it in GitHub Desktop.

Select an option

Save istumpf/b2477b58bfdb5f24607e6bcdd1cc94fa to your computer and use it in GitHub Desktop.
const azure = require('azure-storage');
const { readConfig } = require('./config');
const config = readConfig();
const blobService = azure.createBlobService(config.azure.connectionString);
const container = config.azure.storageContainer;
const deleteFromStorage = async ({ caminho, cb }) => {
blobService.deleteBlobIfExists(
container,
caminho,
function(error, result) {
return cb(error, result);
}
);
};
const uploadToStorage = async ({ fetchResponse, caminho, contentType, cb }) => {
const writeStream = blobService.createWriteStreamToBlockBlob(
container,
caminho,
{
contentSettings: {
contentType: contentType
}
},
function(error, result) {
return cb(error, result);
}
);
return await fetchResponse.body.pipe(writeStream);
};
module.exports = {
uploadToStorage : uploadToStorage,
deleteFromStorage : deleteFromStorage
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment