我想在将文件上传到Azure blob存储方面获得帮助。 我实际上希望能够从容器的后端获取SAS令牌,并希望能够使用react Web应用程序将文件上传到该容器。
我使用this作为参考,但无法继续。
答案 0 :(得分:1)
使用generateBlobSASQueryParameters
软件包中的@azure/storage-blob
函数。
我使用generateBlobSASQueryParameters
的方式是:
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;