当尝试连接到azure-blob-storage并试图包装连接信息并使用StorageSharedKEyCredential时,我得到了以下错误:
StorageSharedKeyCredential is not a constructor我使用的是Vue.js。
还有一个类似的问题,版本不同,所以我检查了文档和版本。
(使用版本:"@ azure / storage-blob":"^ 12.1.1")
如何使用StorageSharedKEyCredential?
最后,我希望能够访问Azure Blob存储。
请让我知道。
===========================
代码是这样的。
const { StorageSharedKeyCredential,BlobServiceClient } = require("@azure/storage-blob");
mounted: function () {
this.init()
},
methods: {
init: function () {
this.accessBlob()
.then(() => console.log('Done'))
.catch((ex) => console.log('catch:', ex.message));
},
accessBlob: async function(){
const config = require("./config/config.json");
const ACCOUNT_NAME = config.storageAccount;
const ACCOUNT_ACCESS_KEY = config.storageAccessKey;
// Create the BlobServiceClient object which will be used to create a container client
const credentials = new StorageSharedKeyCredential(ACCOUNT_NAME, ACCOUNT_ACCESS_KEY);
const blobServiceClient = new BlobServiceClient(
`https://${ACCOUNT_NAME}.blob.core.windows.net`,
credentials
);
let i = 1;
for await (const container of blobServiceClient.listContainers()) {
console.log(`Container ${i++}: ${container.name}`);
}
}
}===========================
(参考:SharedKeyCredential is not a constructor - Azure Blob Storage + Nodejs)
发布于 2020-04-20 12:11:14
由于SharedKeyCredential仅在运行时可用,因此您需要使用共享访问签名(SAS)或OAuth令牌进行身份验证。
发布于 2020-04-20 12:12:17
如何使用StorageSharedKEyCredential?
简单的答案是你不能,因为你的代码将在浏览器中运行(或者换句话说,在客户端),使用StorageSharedKeyCredential会将你的帐号密钥暴露给所有人,这是一个巨大的安全风险。
如果从基于浏览器的应用程序中使用JS,则需要使用Shared Access Signature。你可以在这里找到一个相同的例子:https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob#with-sas-token。
https://stackoverflow.com/questions/61314949
复制相似问题