How to use the @azure/storage-blob.Aborter.timeout 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
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);

  // get file stats
  let fileStats = await getFileStats(localFilePath);

  // parallel uploading
  let uploadStatus = await uploadStreamToBlockBlob(
    Aborter.timeout(30 * 60 * 1000), // Abort uploading with timeout in 30mins
    fs.createReadStream(localFilePath),
    blockBlobURL,
    4 * 1024 * 1024, // 4MB block size
    20, // 20 concurrency
    {
      progress: ev => console.log(ev)
    }
    );
    console.log('uploadStreamToBlockBlob success');
    // END STORAGE CODE

    // notify IoT Hub of upload to blob status (success/faillure)
    await client.notifyBlobUploadStatus(uploadStatus);
    return 0;
}
github serverless / serverless-azure-functions / src / services / azureBlobStorageService.ts View on Github external
public async downloadBinary(containerName: string, blobName: string, targetPath: string) {
    const blockBlobUrl = this.getBlockBlobURL(containerName, blobName);
    const props = await blockBlobUrl.getProperties(Aborter.none);
    const buffer = Buffer.alloc(props.contentLength);
    await downloadBlobToBuffer(
      Aborter.timeout(30 * 60 * 1000),
      buffer,
      blockBlobUrl,
      0,
      undefined,
      {
        blockSize: 4 * 1024 * 1024, // 4MB block size
        parallelism: 20, // 20 concurrency
      }
    );
    fs.writeFileSync(targetPath, buffer, "binary");
  }
github microsoft / BotFramework-WebChat / samples / 20.a.upload-to-azure-storage / bot / src / createBot.js View on Github external
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 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`);
    
    await uploadLocalFile(aborter, containerURL, localFilePath);
    console.log(`Local file "${localFilePath}" is uploaded`);

    await uploadStream(aborter, containerURL, localFilePath);
    console.log(`Local file "${localFilePath}" is uploaded as a stream`);
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'));

  await Promise.all(
    segment.blobItems
      .filter(({ name }) => extname(name) === TARGET_EXTNAME)
      .map(async ({ name }) => {
        console.log(`Setting content type for blob "${ name }"`);
github Azure / ng-deploy-azure / src / util / azure / account.ts View on Github external
export async function setStaticSiteToPublic(serviceURL: ServiceURL) {
  await serviceURL.setProperties(Aborter.timeout(30 * 60 * 60 * 1000), {
    staticWebsite: {
      enabled: true,
      indexDocument: 'index.html',
      errorDocument404Path: 'index.html'
    }
  });
}
github Soluto / dynamico / server / azure-blob-storage / lib / index.ts View on Github external
constructor({
    container,
    indexBlobName = 'index.json',
    timeout = 30 * 60000,
    concurrentConnections = 5
  }: AzureBlobStorageOptions) {
    this.container = container;
    this.indexBlobUrl = BlockBlobURL.fromContainerURL(this.container, indexBlobName);
    this.aborter = Aborter.timeout(timeout);
    this.concurrentConnections = concurrentConnections;
  }