0
votes

My web app allows users to upload files. I want to use cloud azure blob storage for this.

Since downloading will be very frequent (more than uploading) I would like to save server computing time and bandwith and serve files directly from the azure blob server.

I believe it is made possible on Google cloud with Firebase (Firestorage). Where you can upload and download directly from the client. (I know authentication and authorization are also managed by firebase so it makes things easier)

Does any similar mechanisms/service exist on Azure?

For example When a user clicks an azure storage download link a trigger would check the JWT for authorization and data would be sent directly to the client from azure storage

1

1 Answers

1
votes

Similar option is available with Azure Blob storage as well. You can use the Storage SDK to access the containers and list/download the blob

With a javascript backend You can either use SAS Token or Azure Storage JavaScript Client Library also supports creating BlobService based on Storage Account Key for authentication besides SAS Token. However, for security concerns, use of a limited time SAS Token, generated by a backend web server using a Stored Access Policy.

Example here

EDIT:

I have not answered the question completely above, However if you want to access the blob storage or download any files from the blob storage you can make use of normal http get request with SAS token generated with any JavaScript application.

With Angualr:

uploadToBLob(files) {
    let formData: FormData = new FormData();
    formData.append("asset", files[0], files[0].name);
    this.http.post(this.baseUrl + 'insertfile', formData)
      .subscribe(result => console.log(result));
  }

  downloadFile(fileName: string) {
    return this.http.get(this.baseUrl + 'DownloadBlob/' + fileName, { responseType: "blob" })
      .subscribe((result: any) => {
        if (result) {
          var blob = new Blob([result]);
          let saveAs = require('file-saver');
          let file = fileName;
          saveAs(blob, file);
          this.fileDownloadInitiated = false;
        }
      }, err => this.errorMessage = err
      );
  }

However the best practice (considering the security) is to have a backend API/Azure function to handle the file upload.