Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
console.log('5. Deleting blob with Shared Access Signature');
sharedBlobService.deleteBlob(containerName, blobName, function (error) {
if (error) return callback(error);
console.log('6. Deleting container');
blobService.deleteContainer(containerName, function (error) {
return callback(error);
public uploadToSasUrl(sasUrl: string, filePath: string): Observable {
const subject = new AsyncSubject();
const { accountUrl, sasToken, container, blob } = this._parseSasUrl(sasUrl);
const service = createBlobServiceWithSas(accountUrl, sasToken);
service.createBlockBlobFromLocalFile(container, blob, filePath,
(error: any, result: BlobService.BlobResult) => {
this.zone.run(() => {
if (error) {
subject.error(ServerError.fromStorage(error));
subject.complete();
}
subject.next(result);
subject.complete();
});
});
return subject.asObservable();
}
return this.resourceManager.getContainers((err, containers) => {
if (err) return callback(err);
const containerDetails = containers[Math.floor(Math.random() * containers.length)];
const blobService = azureStorage.createBlobServiceWithSas(
containerDetails.toURI({ withSas: false, withObjectName: false }),
containerDetails.sas
);
const blobName = `${props.database}__${props.table}__${uuidv4()}`;
const writeStream = blobService.createWriteStreamToBlockBlob(containerDetails.objectName, blobName, (err) => {
if (err) return callback(err);
const blobUri = `${containerDetails.toURI({ withSas: false })}/${blobName}?${containerDetails.sas}`;
return this.ingestFromBlob(new BlobDescriptor(blobUri, descriptor.size), props, callback);
});
descriptor.pipe(writeStream);
});
}
public uploadToSasUrl(sasUrl: string, filePath: string): Observable {
const subject = new AsyncSubject();
const { accountUrl, sasToken, container, blob } = this._parseSasUrl(sasUrl);
const service = createBlobServiceWithSas(accountUrl, sasToken);
service.createBlockBlobFromLocalFile(container, blob, filePath,
(error: any, result: BlobService.BlobResult) => {
this.zone.run(() => {
if (error) {
subject.error(ServerError.fromStorage(error));
subject.complete();
}
subject.next(result);
subject.complete();
});
});
return subject.asObservable();
}
this.resourceManager.getContainers((err, containers) => {
if (err) return callback(err);
const containerDetails = containers[Math.floor(Math.random() * containers.length)];
const blobService = azureStorage.createBlobServiceWithSas(containerDetails.toURI({
withObjectName: false,
withSas: false
}), containerDetails.sas);
blobService.createBlockBlobFromLocalFile(containerDetails.objectName, blobName, fileToUpload, (err) => {
if (err) return callback(err);
const blobUri = `${containerDetails.toURI({ withSas: false })}/${blobName}?${containerDetails.sas}`;
return this.ingestFromBlob(new BlobDescriptor(blobUri, descriptor.size, descriptor.sourceId), props, callback);
});
});