How to use the @azure/storage-blob.StorageURL.newPipeline function in @azure/storage-blob

To help you get started, we’ve selected a few @azure/storage-blob 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 / azure-iot-sdk-node / device / samples / upload_to_blob_v2.js View on Github external
async function uploadToBlob(localFilePath, client) {
  // OUR CODE
  let blobInfo = await client.getBlobSharedAccessSignature(blobName);
  if (!blobInfo) {
    throw new errors.ArgumentError('Invalid upload parameters');
  }

  // STORAGE BLOB CODE
  const pipeline = StorageURL.newPipeline(new AnonymousCredential(), {
    retryOptions: { maxTries: 4 },
    telemetry: { value: 'HighLevelSample V1.0.0' }, // Customized telemetry string
    keepAliveOptions: {
      enable: false
    }
  });

  const serviceURL = new ServiceURL(
    `https://${blobInfo.hostName}/${blobInfo.sasToken}`,
    pipeline
  );  

  // initialize the blockBlobURL to a new blob
  const containerURL = ContainerURL.fromServiceURL(serviceURL, blobInfo.containerName);
  const blobURL = BlobURL.fromContainerURL(containerURL, blobInfo.blobName);
  const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL);
github HomecareHomebase / azure-bake / ingredient / ingredient-storage / src / plugin.ts View on Github external
private async ConfigureDiagnosticSettings(params: any, util: any) {
        let accountName: string;
        let accountKey: string;

        //Get blob storage properties
        accountName = params["storageAccountName"].value;
        const storageUtils = new StorageUtils(this._ctx);
        accountKey = await storageUtils.get_primary_key(accountName, await util.resource_group())
        const credentials = new SharedKeyCredential(accountName, accountKey);
        const pipeline = StorageURL.newPipeline(credentials, {
            // Enable logger when debugging
            // logger: new ConsoleHttpPipelineLogger(HttpPipelineLogLevel.INFO)
        });
        const blobPrimaryURL = `https://${accountName}.blob.core.windows.net/`;
        var serviceURL = new ServiceURL(blobPrimaryURL, pipeline)
        const serviceProperties = await serviceURL.getProperties(Aborter.none);

        //Get Bake variables for diagnostic settings.  Default to "true" (enabled) and 10 days data retention.
        let blobDiagnosticHourlyMetricsEnabled: string = await util.variable("blobDiagnosticHourlyMetricsEnabled") || "true"
        let blobDiagnosticHourlyMetricsRetentionDays = await util.variable("blobDiagnosticHourlyMetricsRetentionDays") || 10
        let blobDiagnosticMinuteMetricsEnabled: string = await util.variable("blobDiagnosticMinuteMetricsEnabled") || "true"
        let blobDiagnosticMinuteMetricsRetentionDays = await util.variable("blobDiagnosticMinuteMetricsRetentionDays") || 10
        let blobDiagnosticLoggingEnabled: string = await util.variable("blobDiagnosticLoggingEnabled") || "true"
        let blobDiagnosticLoggingRetentionDays = await util.variable("blobDiagnosticLoggingRetentionDays") || 10

        //Workaround due to issues using boolean data type for Bake variables
github microsoft / BotFramework-WebChat / samples / 20.a.upload-to-azure-storage / bot / src / createBot.js View on Github external
bot.onEvent(async (context, next) => {
    const {
      activity: { name, value }
    } = context;

    // Intercepts all "upload" event activities.
    if (name === 'upload') {
      // For async operations that are outside of BotBuilder, we should use proactive messaging.
      const reference = TurnContext.getConversationReference(context.activity);

      // The file upload validation could take more than a second, we should send a typing indicator.
      await context.sendActivity({ type: 'typing' });

      const { files } = value;
      const pipeline = StorageURL.newPipeline(
        new SharedKeyCredential(AZURE_STORAGE_ACCOUNT_NAME, AZURE_STORAGE_ACCOUNT_KEY)
      );

      const properties = await Promise.all(
        files.map(file => {
          // You should verify the URL if it is from the blob account and container that this service owned.

          const blockBlobURL = new BlockBlobURL(file, pipeline);

          // After the bot receives the URL, it should validate its content and associate it with the user ID.
          // If the content needs to be kept for longer than a day, we should copy it to another blob container because we set up a rule to clean the storage daily.

          return blockBlobURL.getProperties(Aborter.timeout(5000));
        })
      );
github microsoft / BotFramework-WebChat / scripts / setJavaScriptContentType.js View on Github external
async function main(accountName, accountKey, container, prefix) {
  const containerURL = ContainerURL.fromServiceURL(
    new ServiceURL(
      `https://${ accountName }.blob.core.windows.net`,
      StorageURL.newPipeline(new SharedKeyCredential(accountName, accountKey))
    ),
    container
  );

  const { segment } = await containerURL.listBlobHierarchySegment(
    Aborter.timeout(BLOB_OPERATION_TIMEOUT),
    BLOB_DELIMITER,
    null,
    { prefix }
  );

  console.log([
    `Found ${ segment.blobItems.length } blob in container "${ container }" with prefix "${ prefix || '' }"`,
    ...segment.blobItems.map(({ name, properties: { contentLength } }) => `  ${ name } (${ contentLength } bytes)`),
    ''
  ].join('\n'));
github Azure-Samples / azure-storage-js-v10-quickstart / v10 / index.js View on Github external
async function execute() {

    const containerName = "demo";
    const blobName = "quickstart.txt";
    const content = "Hello Node SDK";
    const localFilePath = "../readme.md";

    const credentials = new SharedKeyCredential(STORAGE_ACCOUNT_NAME, ACCOUNT_ACCESS_KEY);
    const pipeline = StorageURL.newPipeline(credentials);
    const serviceURL = new ServiceURL(`https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net`, pipeline);
    
    const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
    const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName);
    
    const aborter = Aborter.timeout(30 * ONE_MINUTE);

    await containerURL.create(aborter);
    console.log(`Container: "${containerName}" is created`);

    console.log("Containers:");
    await showContainerNames(aborter, serviceURL);

    await blockBlobURL.upload(aborter, content, content.length);
    console.log(`Blob "${blobName}" is uploaded`);
github serverless / serverless-azure-functions / src / services / azureBlobStorageService.ts View on Github external
private getServiceURL(): ServiceURL {
    this.checkInitialization();

    const pipeline = StorageURL.newPipeline(this.storageCredential);
    const accountUrl = this.accountUrl;
    const serviceUrl = new ServiceURL(
      accountUrl,
      pipeline,
    );
    return serviceUrl;
  }
github serverless / multicloud / azure / src / services / azureBlobStorage.ts View on Github external
public constructor() {
    const sharedKeyCredential = new SharedKeyCredential(
      process.env.azAccount,
      process.env.azAccountKey
    );
    const pipeline = StorageURL.newPipeline(sharedKeyCredential);

    this.service = new ServiceURL(
      `https://${process.env.azAccount}.blob.core.windows.net`,
      pipeline
    );
  }
github microsoft / VoTT / src / providers / storage / azureBlobStorage.ts View on Github external
private getServiceURL(): ServiceURL {
        const credential = this.getCredential();
        const pipeline = StorageURL.newPipeline(credential);
        const accountUrl = this.getAccountUrl();
        const serviceUrl = new ServiceURL(
            accountUrl,
            pipeline,
        );
        return serviceUrl;
    }