gpt4 book ai didi

node.js - SharedKeyCredential 不是构造函数 - Azure Blob 存储 + Nodejs

转载 作者:行者123 更新时间:2023-12-03 01:00:41 26 4
gpt4 key购买 nike

我正在尝试删除 aucitonImages 容器中的图像,但是当我从 postman 执行该函数时,我得到 SharedKeyCredential is not a constructor 我一直在关注 documentation我想我已经完成了所有设置,但我没有看到我的代码与文档有什么不同。我感谢任何帮助!

app.delete("/api/removeauctionimages", upload, async (req, res, next) => {
const { ContainerURL, ServiceURL, StorageURL, SharedKeyCredential } = require("@azure/storage-blob");
const credentials = new SharedKeyCredential(process.env.AZURE_STORAGE_ACCOUNT, process.env.AZURE_STORAGE_ACCESS_KEY);
const pipeline = StorageURL.newPipeline(credentials);
const serviceURL = new ServiceURL(`https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net`, pipeline);
const containerName = "auctionImages";
const blobName = "myimage.png";



const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName);
await blockBlobURL.delete(aborter)
console.log(`Block blob "${blobName}" is deleted`);

});

最佳答案

基于 SDK 版本 12.1.0 文档 here ,看起来 Microsoft 将 SharedKeyCredential 更改为 StorageSharedKeyCredential

你能尝试一下吗?

此外,请在此处查看此版本 SDK 的示例:https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/storage/storage-blob/samples/javascript .

<小时/>

这是我使用 Node SDK v12.1.0 编写的代码:

const { StorageSharedKeyCredential, BlobServiceClient } = require("@azure/storage-blob");
const sharedKeyCredential = new StorageSharedKeyCredential(process.env.AZURE_STORAGE_ACCOUNT, process.env.AZURE_STORAGE_ACCESS_KEY);


const blobServiceClient = new BlobServiceClient(
`https://${process.env.AZURE_STORAGE_ACCOUNT}.blob.core.windows.net`,
sharedKeyCredential
);

const containerName = `temp`;
const blobName = 'test.png';
const containerClient = blobServiceClient.getContainerClient(containerName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
await blockBlobClient.delete();

关于node.js - SharedKeyCredential 不是构造函数 - Azure Blob 存储 + Nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60873972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com