How to use the azure-storage.createBlobService function in azure-storage

To help you get started, we’ve selected a few azure-storage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure-Samples / storage-blob-node-getting-started / advanced.js View on Github external
function leaseBlob(callback) {
  // Create a blob client for interacting with the blob service from connection string
  // How to create a storage connection string - http://msdn.microsoft.com/en-us/library/azure/ee758697.aspx
  var blobService = storage.createBlobService(config.connectionString);

  var containerName = "demoleaseblobcontainer-" + guid.v1();
  var blobName = 'exclusive';

  console.log('1. Create Container');
  blobService.createContainerIfNotExists(containerName, function (error) {
    if (error) return callback(error);

    console.log('2. Create blob');
    blobService.createBlockBlobFromText(containerName, blobName, 'blob created', function (error) {
      if (error) return callback(error);

      console.log('3. Acquire lease on blob');
      blobService.acquireLease(containerName, blobName, { leaseDuration: 15 }, function (error, leaseResult) {
        if (error) return callback(error);
github compulim / azure-storage-fs / src / AzureBlobFS.js View on Github external
constructor(account, secret, container, options = DEFAULT_OPTIONS) {
    if (account && REQUIRED_BLOB_SERVICE_APIS.every(name => typeof account[name] === 'function')) {
      // If account looks like a BlobService (with all of our required APIs), then use it
      this._blobService = account;
      container = secret;
      options = container;
    } else {
      this._blobService = require('azure-storage').createBlobService(account, secret);
    }

    this.options = options;

    this._blobServicePromised = promisifyObject(
      this._blobService,
      REQUIRED_BLOB_SERVICE_APIS
    );

    this.container = container;
    this.promise = {};

    [
      'mkdir',
      'open',
      'readdir',
github Azure / mmlspark / tools / misc / get-stats.js View on Github external
module.exports = ctx => {
  let blob = az.createBlobService(process.env.MMLSparkStorage);
  let gh   = new ghAPI();
  let timeStamp = new Date().toISOString()
                        .replace(/:[0-9][0-9]\.[0-9]+Z/, "").replace(/T/, " ");

  let getPaged = (state, combine) => r =>
    !gh.hasNextPage(r) ? Promise.resolve(combine(state, r.data))
    : gh.getNextPage(r).then(getPaged(combine(state, r.data), combine));
  let getAllContributors = getPaged([], (st,d) => st.concat(d.map(x => x.login)))
  let getAllIssues = getPaged([[],[]], (st,d) =>
    [st[0].concat(d.filter(x => !("pull_request" in x)).map(x => "#"+x.number)),
     st[1].concat(d.filter(x =>  ("pull_request" in x)).map(x => "#"+x.number))])

  // To initialize the append blob (delete the rest when doing this to avoid races):
  // blob.createAppendBlobFromText("stats", "log", `initial text`,
  //   (err) => { if (err) ctx.done(err); else { ctx.log(">>> DONE!"); ctx.done(); }});
github Azure / api-management-developer-portal / scripts / upload.js View on Github external
}
        });
    });
}

async function uploadFiles() {
    const fileNames = listFilesInDirectory(mediaPath);

    for (const fileName of fileNames) {
        const blobName = path.basename(fileName).split(".")[0];
        console.log(`Uploading file: ${blobName}`);
        await upload(fileName, blobName);
    }
}

const blobService = storage.createBlobService(connectionString);

uploadFiles()
    .then(() => {
        console.log("DONE");
        process.exit();
    })
    .catch(error => {
        console.log(error);
    })
github lukasreichart / skipper-azure / index.js View on Github external
module.exports = function SkipperAzure( globalOptions ) {
  globalOptions = globalOptions || {};

  var blobService = azure.createBlobService( globalOptions.key,
    globalOptions.secret );

  var adapter = {

    read: function( fd, cb ) {
      var prefix = fd;

      var res = blobService.createReadStream( globalOptions.container, prefix, function( err ) {
        if ( err ) {
          cb( err );
        }
      });

      res.pipe(concat(function (data) {
        return cb(null, data);
      }));
github CatalystCode / project-fortis / project-fortis-services / src / clients / storage / BlobStorageClient.js View on Github external
function uploadFile(container, fileName, path, expiryMinutes) {
  const client = azure.createBlobService(userFilesBlobAccountName, userFilesBlobAccountKey);

  return new Promise((resolve, reject) => {
    client.createContainerIfNotExists(container, (error) => {
      if (error) return reject(error);

      client.createBlockBlobFromLocalFile(container, fileName, path, (error) => {
        if (error) return reject(error);

        const expires = minutesFromNow(expiryMinutes);
        const accessSignature = client.generateSharedAccessSignature(container, fileName, { AccessPolicy: { Expiry: expires, Permissions: READ } });
        const url = client.getUrl(container, fileName, accessSignature, true);

        resolve({
          url,
          expires
        });
github keystonejs / keystone-classic / fields / types / azurefile / AzureFileType.js View on Github external
var doUpload = function () {
		var blobService = azure.createBlobService();
		var container = field.options.containerFormatter(item, file.name);

		blobService.createContainerIfNotExists(container, { publicAccessLevel: 'blob' }, function (err) {

			if (err) return callback(err);

			blobService.createBlockBlobFromLocalFile(container, field.options.filenameFormatter(item, file.name), file.path, function (err, blob, res) {

				if (err) return callback(err);

				var fileData = {
					filename: blob.blob,
					size: file.size,
					filetype: filetype,
					etag: blob.etag,
					container: container,
github MantaCodeDevs / multer-azure-storage / index.js View on Github external
azureUseConnectionString = true;
        }

        if (!opts.containerName) missingParameters.push("containerName")


        if (missingParameters.length > 0) {
          throw new Error('Missing required parameter' + (missingParameters.length > 1 ? 's' : '') + ' from the options of MulterAzureStorage: ' + missingParameters.join(', '))
        }

        this.containerName = opts.containerName

        this.fileName = opts.fileName

        if(azureUseConnectionString){
            this.blobService = azure.createBlobService(opts.azureStorageConnectionString)
        } else {
            this.blobService = azure.createBlobService(
                opts.azureStorageAccount,
                opts.azureStorageAccessKey)
        }

        let security = opts.containerSecurity || defaultSecurity

        this.blobService.createContainerIfNotExists(this.containerName, { publicAccessLevel : security }, (err, result, response) => {
            if (err) {
                this.containerError = true
                throw new Error('Cannot use container. Check if provided options are correct.')
            }

            this.containerCreated = true
github DFEAGILEDEVOPS / MTC / admin / services / data-access / azure-file.data.service.js View on Github external
const azure = require('azure-storage')
const config = require('../../config')

const blobService = config.AZURE_STORAGE_CONNECTION_STRING ? azure.createBlobService() : {
  createBlockBlobFromText: () => { return { name: 'test_error.csv' } },
  getBlobToText: () => 'text',
  getBlobToStream: (container, blob, fStream, cb) => {
    fStream.write('binary')
    fStream.end()
    cb()
  },
  createContainerIfNotExists: () => {}
}

const azureUploadFile = async (container, remoteFilename, text, streamLength) => {
  await new Promise((resolve, reject) => {
    blobService.createContainerIfNotExists(container, null, (error) => {
      if (error) reject(error)
      resolve()
    })
github danielgerlag / workflow-es / providers / workflow-es-azure / src / azure-lock-manager.ts View on Github external
constructor(connectionString: string) {
        var self = this;
        this.blobService = createBlobService(connectionString);
        this.blobService.createContainerIfNotExists(this.containerId, (error: Error, result: BlobService.ContainerResult, response: ServiceResponse): void => {
            //TODO: log
            self.renewTimer = setInterval(this.renewLeases, 45, self);
        });    
    }