Created
February 9, 2018 10:43
-
-
Save istumpf/b2477b58bfdb5f24607e6bcdd1cc94fa to your computer and use it in GitHub Desktop.
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
| 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