简体   繁体   中英

how to upload a file to Azure storage blob Container after getting sasQueryParameter in SDK v10 using nodejs?

I would like to have some help with uploading a file to Azure blob storage. I actually want to be able to get SAS token from the backend for the container and want to be able to upload a file to that container using react web app.

I used this for reference, but couldn't get going.

use generateBlobSASQueryParameters function from @azure/storage-blob package.

the way I used generateBlobSASQueryParameters is :

const {
  BlobSASPermissions,
  SharedKeyCredential,
  generateBlobSASQueryParameters,
} = require("@azure/storage-blob");

const {
  STORAGE_ACCOUNT_KEY,
  STORAGE_ACCOUNT_NAME,
  CONTAINERS,
} = require("./Constants/blobStorage"); // get these from azure storage account

const generateSasQueryToken = () => {
  const sharedKeyCredential = new SharedKeyCredential(STORAGE_ACCOUNT_NAME, STORAGE_ACCOUNT_KEY);
  const permissions = BlobSASPermissions.parse("racwd");
  const startDate = new Date();
  const expiryDate = new Date(startDate);
  expiryDate.setMinutes(startDate.getMinutes() + 100);
  startDate.setMinutes(startDate.getMinutes() - 100);
  const queryParams = generateBlobSASQueryParameters(
    {
      containerName: CONTAINERS.IMAGE,
      permissions: permissions.toString(),
      startTime: startDate,
      expiryTime: expiryDate,
    },
    sharedKeyCredential,
  );
  return {
    SAS_STRING: queryParams.toString(),
    CONTAINER_NAME: CONTAINERS.IMAGE,
    URL: `https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net/`,
  };
};

module.exports = generateSasQueryToken; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM