Skip to content

Instantly share code, notes, and snippets.

@timothytavarez
Created June 26, 2017 01:10
Show Gist options
  • Save timothytavarez/7b2ffd859b5ab6267749220249d406fd to your computer and use it in GitHub Desktop.
Save timothytavarez/7b2ffd859b5ab6267749220249d406fd to your computer and use it in GitHub Desktop.
Azure Blob Storage Uploader
'use strict';
const azure = require('azure-storage');
const uuidv1 = require('uuid/v1');
const path = require('path');
const blobService = azure.createBlobService('azuredotjsblob', // fill in your value here.
'connection_key', // fill in your value here.
'blob_service_endpoint'); // fill in your value here.
let container = 'imagecontainer', // fill in your value here.
upload = process.argv[2],
extName = path.extname(upload),
blobName = uuidv1() + extName;
function uploadToBlob() {
blobService.createBlockBlobFromLocalFile(container, blobName, upload, function (error, result) {
if (!error) {
let id = blobService.getUrl(container, blobName);
console.log(`${blobName} successfully uploaded to Azure Blob Storage. URL:`)
return console.log(id);
}
return console.error(error);
})
}
uploadToBlob();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment