Home > database >  How to connect to blob container using SAS url in javascript?
How to connect to blob container using SAS url in javascript?

Time:05-12

i want to connect straight to container not to storage account using container's url with SAS.

For now i have code that work:

private async getContainer() {   
    const blobServiceClient = new BlobServiceClient(this.props.sasToken);
    let baseContainer = blobServiceClient.getContainerClient(this.props.containerName);
    this.setState(state => ({ ...state, container: baseContainer }));
};

But in property this.props.sasToken i need to pass url to Storage account and container name.

Is it possible to connect to container using url with SAS only for this container? In Azure Storage Explorer it is possible but how to manage the same result programatically?

CodePudding user response:

Please use ContainerClient(string, PipelineLike) constructor to create an instance of ContainerClient. You will pass the container SAS URL as the first parameter.

Your code would be something like:

let baseContainer = new ContainerClient(this.props.sasToken);
this.setState(state => ({ ...state, container: baseContainer }));
  • Related