How to use the azure-storage.BlobUtilities 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 microsoft / ghcrawler / providers / storage / storageDocStore.js View on Github external
callback => {
        var started = new Date().getTime();
        this.service.listBlobsSegmented(this.name, continuationToken, { include: azure.BlobUtilities.BlobListingDetails.METADATA, location: azure.StorageUtilities.LocationMode.PRIMARY_THEN_SECONDARY }, function (err, result, response) {
          // metricsClient.trackDependency(url.parse(blobService.host.primaryHost).hostname, 'listBlobsSegmented', (new Date().getTime() - started), !err, "Http", { 'Container name': 'download', 'Continuation token present': result == null ? false : (result.continuationToken != null), 'Blob count': result == null ? 0 : result.entries.length });

          if (err) {
            continuationToken = null;
            // metricsClient.trackError(err);
            callback(err);
          }
          entries = entries.concat(result.entries.map(entry => {
            const blobMetadata = entry.metadata;
            return {
              version: blobMetadata.version,
              etag: blobMetadata.etag,
              type: blobMetadata.type,
              url: blobMetadata.url,
              urn: blobMetadata.urn,
              fetchedAt: blobMetadata.fetchedat,
github Azure-Samples / storage-blob-node-getting-started / advanced.js View on Github external
blobService.createContainerIfNotExists(containerName, function (error) {
    if (error) return callback(error);

    console.log('2. Getting Shared Access Signature for container');
    var expiryDate = new Date();

    expiryDate.setMinutes(expiryDate.getMinutes() + 30);

    var sharedAccessPolicy = {
      AccessPolicy: {
        Permissions: storage.BlobUtilities.SharedAccessPermissions.READ +
        storage.BlobUtilities.SharedAccessPermissions.WRITE +
        storage.BlobUtilities.SharedAccessPermissions.DELETE +
        storage.BlobUtilities.SharedAccessPermissions.LIST,
        Expiry: expiryDate
      }
    };

    var sas = blobService.generateSharedAccessSignature(containerName, null, sharedAccessPolicy);

    var sharedBlobService = storage.createBlobServiceWithSas(blobService.host, sas);

    console.log('3. Creating blob with Shared Access Signature');
    sharedBlobService.createBlockBlobFromText(containerName, blobName, 'test data', function (error) {
      if (error) return callback(error);

      console.log('4. Listing blobs in container with Shared Access Signature');
      listBlobs(sharedBlobService, containerName, null, null, null, function (error, blobs) {
        if (error) return callback(error);
github Azure / azure-storage-node / examples / blobuploader / app.js View on Github external
function setPermissions() {
  var options = { publicAccessLevel: azure.BlobUtilities.BlobContainerPublicAccessType.BLOB };
  blobClient.setContainerAcl(containerName, null, options, function (error) {
    if (error) {
      console.log(error);
    } 
  });
}
github Azure-Samples / storage-blob-node-getting-started / advanced.js View on Github external
blobService.createContainerIfNotExists(containerName, function (error) {
    if (error) return callback(error);

    console.log('2. Getting Shared Access Signature for container');
    var expiryDate = new Date();

    expiryDate.setMinutes(expiryDate.getMinutes() + 30);

    var sharedAccessPolicy = {
      AccessPolicy: {
        Permissions: storage.BlobUtilities.SharedAccessPermissions.READ +
        storage.BlobUtilities.SharedAccessPermissions.WRITE +
        storage.BlobUtilities.SharedAccessPermissions.DELETE +
        storage.BlobUtilities.SharedAccessPermissions.LIST,
        Expiry: expiryDate
      }
    };

    var sas = blobService.generateSharedAccessSignature(containerName, null, sharedAccessPolicy);

    var sharedBlobService = storage.createBlobServiceWithSas(blobService.host, sas);

    console.log('3. Creating blob with Shared Access Signature');
    sharedBlobService.createBlockBlobFromText(containerName, blobName, 'test data', function (error) {
      if (error) return callback(error);

      console.log('4. Listing blobs in container with Shared Access Signature');
github Sunbird-Ed / SunbirdEd-portal / src / app / helpers / eCreds / uploadUserHelper.js View on Github external
blobService.createBlockBlobFromLocalFile(containerName, path.basename(filePath), filePath, (err, result, response) => {
        if (!err && result) {
            var startDate = new Date();
            var expiryDate = new Date(startDate);
            expiryDate.setMinutes(startDate.getMinutes() + 3600);
            startDate.setMinutes(startDate.getMinutes() - 3600);
            var sharedAccessPolicy = {
                AccessPolicy: {
                    Permissions: azure.BlobUtilities.SharedAccessPermissions.READ,
                    Start: startDate,
                    Expiry: expiryDate
                }
            };
            var token = blobService.generateSharedAccessSignature(containerName, path.basename(filePath), sharedAccessPolicy);
            var sasUrl = blobService.getUrl(containerName, path.basename(filePath), token);
            console.log('upload successful to azure');
            cb(null, { signedUrl: sasUrl, fileDetails: result });
        } else {
            console.log('upload failed to azure', err);
            cb(err, null);
        }
    })
}
github CatalystCode / project-fortis / project-fortis-services / src / clients / storage / BlobStorageClient.js View on Github external
'use strict';

const Promise = require('promise');
const request = require('request');
const { trackDependency } = require('../appinsights/AppInsightsClient');
const azure = require('azure-storage');
const { minutesFromNow } = azure.date;
const { READ } = azure.BlobUtilities.SharedAccessPermissions;

const {
  userFilesBlobAccountKey, userFilesBlobAccountName
} = require('../../../config').storage;

/**
 * @param {string} uri
 * @returns {Promise.>}
*/
function fetchJson(uri) {
  return new Promise((resolve, reject) => {
    request.get(uri, (err, response, body) => {
      if(err || response.statusCode !== 200) {
        return reject(`Unable to get json for uri ${uri}: ${err}`);
      }
github CatalystCode / VoTT-web / api / services / BlobService.js View on Github external
createSAS: (containerName, blobName, durationInMinutes) => {
    const startDate = new Date();
    const expiryDate = new Date(startDate);
    const expiryMinutes = startDate.getMinutes() + (durationInMinutes ? durationInMinutes : 10);
    expiryDate.setMinutes(expiryMinutes);

    const BlobUtilities = azure.BlobUtilities;
    const sharedAccessPolicy = {
      AccessPolicy: {
        Permissions: BlobUtilities.SharedAccessPermissions.WRITE,
        Start: startDate,
        Expiry: expiryDate
      }
    };

    if (!blobName) {
      blobName = uuid();
    }

    const signature = blobService.generateSharedAccessSignature(
      containerName,
      blobName,
      sharedAccessPolicy
github microsoft / azure-pipelines-tasks / Tasks / AzureFunctionAppV1 / deploymentProvider / ConsumptionWebAppDeploymentProvider.ts View on Github external
blobService.createBlockBlobFromLocalFile(containerName, blobName, fileName, (error, result) => {
                if (error) {
                    defer.reject(error);
                }

                //generating SAS URL
                let startDate = new Date();
                let expiryDate = new Date(startDate);
                expiryDate.setFullYear(startDate.getUTCFullYear() + 1);
                startDate.setMinutes(startDate.getMinutes()-5);
            
                let sharedAccessPolicy = {
                    AccessPolicy: {
                        Permissions: azureStorage.BlobUtilities.SharedAccessPermissions.READ,
                        Start: startDate,
                        Expiry: expiryDate
                    }
                };
            
                let token = blobService.generateSharedAccessSignature(containerName, blobName, sharedAccessPolicy);
                let sasUrl = blobService.getUrl(containerName, blobName, token);
                let index = sasUrl.indexOf("?");
                let sasToken: string = sasUrl.substring(index + 1);
                tl.setVariable('SAS_TOKEN', sasToken, true);
                tl.debug(`SAS URL is: ${sasUrl}`);
                defer.resolve(sasUrl);
            });
        });
github CatalystCode / VoTT-web / src / model / training-request-service.js View on Github external
storageFoundation.createBlockBlobFromText(this.blobService, containerName, blobName, csvText).then(result => {
            const queueName = this.projectService.getTrainQueueName(projectId);
            const url = storageFoundation.createSAS(
                this.blobService,
                containerName,
                blobName,
                60 * 24 * 7,
                azureStorage.BlobUtilities.SharedAccessPermissions.READ
            ).url;
            const queueMessage = JSON.stringify({
                projectId: projectId,
                requestId: requestId,
                url: url
            });
            return storageFoundation.createMessage(this.queueService, queueName, queueMessage).then(result => {
                return storageFoundation.insertEntity(this.tableService, this.trainingRequestsTableName, entity);
            });
        });
    });