当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript azure-storage.createBlobService函数代码示例

本文整理汇总了TypeScript中azure-storage.createBlobService函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createBlobService函数的具体用法?TypeScript createBlobService怎么用?TypeScript createBlobService使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createBlobService函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: async

const writeLog = async (type: string, text: any) => {
    const localFile = `${__dirname}/../logs/${type}-${moment().format("YYYYMMDD")}.log`;
    const targetBlob = `logs/${type}-${moment().format("YYYYMMDD")}.log`;
    let stream: any = '';

    await storage.createBlobService().getBlobToStream(configs.containerName, targetBlob, await fs.createWriteStream(localFile), async (error, result, res) => {
        if (error) {
            stream = await fs.createWriteStream(localFile);
        } else {
            stream = await fs.createWriteStream(localFile, {flags:'a'});
        }

        stream.write(`${moment().format()}: ${text}` + "\n");
        stream.end();

        // // Storageにファイルを遷移
        await stream.on('finish', async () => {
            await storage.createBlobService().createBlockBlobFromLocalFile(configs.containerName, targetBlob, localFile, async function(error, result, response) {
                if (!error) {
                    fs.unlink(localFile, () => {});
                }
            });
        });
    });
}
开发者ID:motionpicture,项目名称:ttts-functions,代码行数:25,代码来源:logHelper.ts

示例2: save

 export function save(file: string, callback: (result: any) => void) {
     let bs = azure.createBlobService();
     bs.createContainerIfNotExists(
         'wackcooncontainer',
         { publicAccessLevel: 'blob' },
         function (error, result, response) {
             if (!error) console.log(result ? 'container created' : 'container existed');
         }
     );
     bs.createBlockBlobFromLocalFile('wackcooncontainer', createGUID(), file, (error, result, response) => {
         if (error) console.log(error);
         console.log('create blog response: ' + response);
     });
 }
开发者ID:DanielEgan,项目名称:wackcoon-device,代码行数:14,代码来源:store.ts

示例3: storeImage

  public storeImage(buffer: Buffer): Promise<string> {
    const key = this.randomPath()
    const container = process.env.SLACKBOT_AZURE_CONTAINER
    const options = {contentSettings: {contentType: "image/png"}}
    const wasb = azure.createBlobService()

    return new Promise<string>((resolve, reject) => {
      wasb.createBlockBlobFromText(container, key, buffer, options, (err, result, response) => {
        if (err) {
          reject(`Azure Error: ${err}`)
        } else {
          const storageAccount = process.env.AZURE_STORAGE_ACCOUNT
          resolve(`https://${storageAccount}.blob.core.windows.net/${container}/${key}`)
        }
      })
    })
  }
开发者ID:DipJar,项目名称:looker-slackbot,代码行数:17,代码来源:azure_store.ts

示例4: Promise

    return await new Promise((resolve ,reject) => {
        storage.createBlobService().getBlobToStream(process.env.AZURE_BLOB_STORAGE, targetBlob, fs.createWriteStream(localFile), err => {
            if (err) {
                return reject(err);
            }
            let stream = fs.createWriteStream(localFile, {flags:'a'});
            const readableStream = fs.createReadStream(localFile)
                .pipe(iconv.decodeStream('SJIS'))
                .pipe(iconv.encodeStream('UTF-8'))
                .pipe(csv.parse());
            
            readableStream.on('data', (record) => {
                docs.push(record);
            });

            readableStream.on('end', () => {
                if (configs.csv.csv_101.useHeader) docs.shift();
                fs.unlink(localFile, () => {});
                return resolve(docs);
            });
        });
    });
开发者ID:motionpicture,项目名称:ttts-functions,代码行数:22,代码来源:index.ts

示例5:

* 2. List the first 10(page size) blobs.
*
* 3. Check whether there are more results.
*
* 4. Repeat 2 and 3 until complete.
*
*/

import * as fs from "fs";
import * as azure from "azure-storage";

var container = 'paginationsample';
var blob = 'contsample';
var blobs = [];

var blobService = azure.createBlobService()
      .withFilter(new azure.ExponentialRetryPolicyFilter());

// optionally set a proxy
/*var proxy = {
  protocol: 'http:',
  host: '127.0.0.1',
  port: 8888
};

blobService.setProxy(proxy);
*/

var totalBlobsCount;
var pageSize;
开发者ID:litek,项目名称:azure-storage-node,代码行数:30,代码来源:continuationsample.ts

示例6: publish

async function publish(commit: string, quality: string, platform: string, type: string, name: string, version: string, _isUpdate: string, file: string, opts: PublishOptions): Promise<void> {
	const isUpdate = _isUpdate === 'true';

	const queuedBy = process.env['BUILD_QUEUEDBY']!;
	const sourceBranch = process.env['BUILD_SOURCEBRANCH']!;
	const isReleased = (
		// Insiders: nightly build from master
		(quality === 'insider' && /^master$|^refs\/heads\/master$/.test(sourceBranch) && /Project Collection Service Accounts|Microsoft.VisualStudio.Services.TFS/.test(queuedBy)) ||

		// Exploration: any build from electron-4.0.x branch
		(quality === 'exploration' && /^electron-4.0.x$|^refs\/heads\/electron-4.0.x$/.test(sourceBranch))
	);

	console.log('Publishing...');
	console.log('Quality:', quality);
	console.log('Platform:', platform);
	console.log('Type:', type);
	console.log('Name:', name);
	console.log('Version:', version);
	console.log('Commit:', commit);
	console.log('Is Update:', isUpdate);
	console.log('Is Released:', isReleased);
	console.log('File:', file);

	const stat = await new Promise<fs.Stats>((c, e) => fs.stat(file, (err, stat) => err ? e(err) : c(stat)));
	const size = stat.size;

	console.log('Size:', size);

	const stream = fs.createReadStream(file);
	const [sha1hash, sha256hash] = await Promise.all([hashStream('sha1', stream), hashStream('sha256', stream)]);

	console.log('SHA1:', sha1hash);
	console.log('SHA256:', sha256hash);

	const blobName = commit + '/' + name;
	const storageAccount = process.env['AZURE_STORAGE_ACCOUNT_2']!;

	const blobService = azure.createBlobService(storageAccount, process.env['AZURE_STORAGE_ACCESS_KEY_2']!)
		.withFilter(new azure.ExponentialRetryPolicyFilter(20));

	await assertContainer(blobService, quality);

	const blobExists = await doesAssetExist(blobService, quality, blobName);

	if (blobExists) {
		console.log(`Blob ${quality}, ${blobName} already exists, not publishing again.`);
		return;
	}

	console.log('Uploading blobs to Azure storage...');

	await uploadBlob(blobService, quality, blobName, file);

	console.log('Blobs successfully uploaded.');

	const config = await getConfig(quality);

	console.log('Quality config:', config);

	const asset: Asset = {
		platform: platform,
		type: type,
		url: `${process.env['AZURE_CDN_URL']}/${quality}/${blobName}`,
		hash: sha1hash,
		sha256hash,
		size
	};

	// Remove this if we ever need to rollback fast updates for windows
	if (/win32/.test(platform)) {
		asset.supportsFastUpdate = true;
	}

	console.log('Asset:', JSON.stringify(asset, null, '  '));

	const release = {
		id: commit,
		timestamp: (new Date()).getTime(),
		version,
		isReleased: config.frozen ? false : isReleased,
		sourceBranch,
		queuedBy,
		assets: [] as Array<Asset>,
		updates: {} as any
	};

	if (!opts['upload-only']) {
		release.assets.push(asset);

		if (isUpdate) {
			release.updates[platform] = type;
		}
	}

	await createOrUpdate(commit, quality, platform, type, release, asset, isUpdate);
}
开发者ID:PKRoma,项目名称:vscode,代码行数:97,代码来源:publish.ts

示例7: upload

async function upload(config, subscription) {

    // create the necessary storage client
    let smClient = get_client(config[optionsKey][authFileKey], subscription, "storage");
    let rmClient = get_client(config[optionsKey][authFileKey], subscription, "resource");

    // Perform some checks to ensure that all necessary resources exist
    // - resource group
    let rgExists = await rmClient.resourceGroups.checkExistence(config[storageAccountKey][groupNameKey]);
    // - storage account
    let saExists = await checkStorageAccountExists(smClient, config[storageAccountKey][storageAccountNameKey]);
    // - container
    let containerExists = await checkContainerExists(smClient, config[storageAccountKey][groupNameKey], config[storageAccountKey][storageAccountNameKey], config[storageAccountKey][containerNameKey]);

    // determine if the credentials file can be located
    if (rgExists && saExists && containerExists) {

        // create blob service so that files can be uploaded
        let sakeys = await smClient.storageAccounts.listKeys(config[storageAccountKey][groupNameKey], config[storageAccountKey][storageAccountNameKey], {});
        let blobService = createBlobService(config[storageAccountKey][storageAccountNameKey], sakeys.keys[0].value);

        // get all the files in the specified directory to be uploaded
        let items = listdir(config[dirsKey][workingKey]);

        // iterate around all the files
        let stats;
        let name;
        for (let item of items) {

            // continue onto the next item if this is is a directory
            stats = lstatSync(item);
            if (stats.isDirectory()) {
                continue;
            }

            // the item is a file
            name = item.replace(/\\/g, "/");

            // create the correct name for the blob
            let stringToCheck = config[dirsKey][workingKey].replace(/\\/g, "/");
            if (stringToCheck.endsWith("/") === false) {
                stringToCheck += "/";
            }
            name = name.replace(stringToCheck, "");

            // upload the item
            blobService.createBlockBlobFromLocalFile(config[storageAccountKey][containerNameKey], name, item, {}, (error, result) => {
                if (error) {
                    console.log("FAILED to upload: %s", getError(error));
                } else {
                    console.log("SUCCESS upload file: %s", item);
                }
            });
        }

    } else {
        console.error("Resource Group \"%s\" exists: %s", config[storageAccountKey][groupNameKey], rgExists);
        console.error("Storage Account \"%s\" exists: %s", config[storageAccountKey][storageAccountNameKey], saExists);
        console.error("Container \"%s\" exists: %s", config[storageAccountKey][containerNameKey], containerExists);
        console.error("Errors have occurred, please ensure that all the above resources exist");
        process.exit(4);
    }
}
开发者ID:ehanlon,项目名称:azure-managed-automate,代码行数:63,代码来源:deploy.ts

示例8: publish

async function publish(commit: string, quality: string, platform: string, type: string, name: string, version: string, _isUpdate: string, file: string, opts: PublishOptions): Promise<void> {
	const isUpdate = _isUpdate === 'true';

	const queuedBy = process.env['BUILD_QUEUEDBY'];
	const sourceBranch = process.env['BUILD_SOURCEBRANCH'];
	const isReleased = quality === 'insider'
		&& /^master$|^refs\/heads\/master$/.test(sourceBranch)
		&& /Project Collection Service Accounts|Microsoft.VisualStudio.Services.TFS/.test(queuedBy);

	console.log('Publishing...');
	console.log('Quality:', quality);
	console.log('Platforn:', platform);
	console.log('Type:', type);
	console.log('Name:', name);
	console.log('Version:', version);
	console.log('Commit:', commit);
	console.log('Is Update:', isUpdate);
	console.log('Is Released:', isReleased);
	console.log('File:', file);

	const stream = fs.createReadStream(file);
	const [sha1hash, sha256hash] = await Promise.all([hashStream('sha1', stream), hashStream('sha256', stream)]);

	console.log('SHA1:', sha1hash);
	console.log('SHA256:', sha256hash);

	const blobName = commit + '/' + name;
	const storageAccount = process.env['AZURE_STORAGE_ACCOUNT_2'];

	const blobService = azure.createBlobService(storageAccount, process.env['AZURE_STORAGE_ACCESS_KEY_2'])
		.withFilter(new azure.ExponentialRetryPolicyFilter());

	const mooncakeBlobService = azure.createBlobService(storageAccount, process.env['MOONCAKE_STORAGE_ACCESS_KEY'], `${storageAccount}.blob.core.chinacloudapi.cn`)
		.withFilter(new azure.ExponentialRetryPolicyFilter());

	await Promise.all([
		assertContainer(blobService, quality),
		assertContainer(mooncakeBlobService, quality)
	]);

	const [blobExists, moooncakeBlobExists] = await Promise.all([
		doesAssetExist(blobService, quality, blobName),
		doesAssetExist(mooncakeBlobService, quality, blobName)
	]);

	if (blobExists || moooncakeBlobExists) {
		console.log(`Blob ${quality}, ${blobName} already exists, not publishing again.`);
		return;
	}

	console.log('Uploading blobs to Azure storage...');

	await Promise.all([
		uploadBlob(blobService, quality, blobName, file),
		uploadBlob(mooncakeBlobService, quality, blobName, file)
	]);

	console.log('Blobs successfully uploaded.');

	const config = await getConfig(quality);

	console.log('Quality config:', config);

	const asset: Asset = {
		platform: platform,
		type: type,
		url: `${process.env['AZURE_CDN_URL']}/${quality}/${blobName}`,
		mooncakeUrl: `${process.env['MOONCAKE_CDN_URL']}/${quality}/${blobName}`,
		hash: sha1hash,
		sha256hash
	};

	const release = {
		id: commit,
		timestamp: (new Date()).getTime(),
		version,
		isReleased: config.frozen ? false : isReleased,
		sourceBranch,
		queuedBy,
		assets: [],
		updates: {} as any
	};

	if (!opts['upload-only']) {
		release.assets.push(asset);

		if (isUpdate) {
			release.updates[platform] = type;
		}
	}

	await createOrUpdate(commit, quality, platform, type, release, asset, isUpdate);
}
开发者ID:FabianLauer,项目名称:vscode,代码行数:93,代码来源:publish.ts

示例9: publish

async function publish(commit: string, quality: string, platform: string, type: string, name: string, version: string, _isUpdate: string, file: string, opts: PublishOptions): Promise<void> {
	const isUpdate = _isUpdate === 'true';

	const queuedBy = process.env['BUILD_QUEUEDBY'];
	const sourceBranch = process.env['BUILD_SOURCEBRANCH'];
	const isReleased = quality === 'insider'
		&& /^master$|^refs\/heads\/master$/.test(sourceBranch)
		&& /Project Collection Service Accounts|Microsoft.VisualStudio.Services.TFS/.test(queuedBy);

	console.log('Publishing...');
	console.log('Quality:', quality);
	console.log('Platform:', platform);
	console.log('Type:', type);
	console.log('Name:', name);
	console.log('Version:', version);
	console.log('Commit:', commit);
	console.log('Is Update:', isUpdate);
	console.log('Is Released:', isReleased);
	console.log('File:', file);

	const stat = await new Promise<fs.Stats>((c, e) => fs.stat(file, (err, stat) => err ? e(err) : c(stat)));
	const size = stat.size;

	console.log('Size:', size);

	const stream = fs.createReadStream(file);
	const [sha1hash, sha256hash] = await Promise.all([hashStream('sha1', stream), hashStream('sha256', stream)]);

	console.log('SHA1:', sha1hash);
	console.log('SHA256:', sha256hash);

	const blobName = commit + '/' + name;
	const storageAccount = process.env['AZURE_STORAGE_ACCOUNT_2'];

	const blobService = azure.createBlobService(storageAccount, process.env['AZURE_STORAGE_ACCESS_KEY_2'])
		.withFilter(new azure.ExponentialRetryPolicyFilter(20));

	// {{SQL CARBON EDIT}}
	await assertContainer(blobService, quality);

	const blobExists = await doesAssetExist(blobService, quality, blobName);

	const promises = [];

	if (!blobExists) {
		promises.push(uploadBlob(blobService, quality, blobName, file));
	}

	// {{SQL CARBON EDIT}}
	if (process.env['MOONCAKE_STORAGE_ACCESS_KEY']) {
		const mooncakeBlobService = azure.createBlobService(storageAccount, process.env['MOONCAKE_STORAGE_ACCESS_KEY'], `${storageAccount}.blob.core.chinacloudapi.cn`)
			.withFilter(new azure.ExponentialRetryPolicyFilter(20));

		// mooncake is fussy and far away, this is needed!
		mooncakeBlobService.defaultClientRequestTimeoutInMs = 10 * 60 * 1000;

		await assertContainer(mooncakeBlobService, quality);

		const mooncakeBlobExists = await doesAssetExist(mooncakeBlobService, quality, blobName);

		if (!mooncakeBlobExists) {
			promises.push(uploadBlob(mooncakeBlobService, quality, blobName, file));
		}
	} else {
		console.log('Skipping Mooncake publishing.');
	}

	if (promises.length === 0) {
		console.log(`Blob ${quality}, ${blobName} already exists, not publishing again.`);
		return;
	}

	console.log('Uploading blobs to Azure storage...');

	await Promise.all(promises);

	console.log('Blobs successfully uploaded.');

	const config = await getConfig(quality);

	console.log('Quality config:', config);

	const asset: Asset = {
		platform: platform,
		type: type,
		url: `${process.env['AZURE_CDN_URL']}/${quality}/${blobName}`,
		// {{SQL CARBON EDIT}}
		mooncakeUrl: process.env['MOONCAKE_CDN_URL'] ? `${process.env['MOONCAKE_CDN_URL']}/${quality}/${blobName}` : undefined,
		hash: sha1hash,
		sha256hash,
		size
	};

	const release = {
		id: commit,
		timestamp: (new Date()).getTime(),
		version,
		isReleased: config.frozen ? false : isReleased,
		sourceBranch,
		queuedBy,
//.........这里部分代码省略.........
开发者ID:AlexxNica,项目名称:sqlopsstudio,代码行数:101,代码来源:publish.ts


注:本文中的azure-storage.createBlobService函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。