簡體   English   中英

SharedKeyCredential 不是構造函數 - Azure Blob 存儲 + Nodejs

[英]SharedKeyCredential is not a constructor - Azure Blob Storage + Nodejs

我想在我的aucitonImages容器刪除圖像,但是當我執行從郵遞員的功能,我得到SharedKeyCredential is not a constructor我一直在關注的文件,我想我擁有了一切設置,但我沒有看到我的代碼與文檔有什么不同。 我感謝任何幫助!

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`);

});

基於here的 SDK 版本 12.1.0 文檔,看起來 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM