SharedKeyCredential не является конструктором. Приложение Azure-Storage реагирует - PullRequest
0 голосов
/ 10 июня 2019

Я пытаюсь использовать следующий код для загрузки блочного объекта в хранилище Azure в приложении реагирования.Однако я получаю следующую ошибку.

TypeError: SharedKeyCredential не является конструктором

Есть идеи?

@ azure / storage-blob@ 10.3.0

import React from 'react';

const {
  Aborter,
  BlobURL,
  BlockBlobURL,
  ContainerURL,
  ServiceURL,
  StorageURL,
  SharedKeyCredential,
  AnonymousCredential,
  TokenCredential
} = require("@azure/storage-blob"); // Change to "@azure/storage-blob" in your package

function App() {
  return (
    <div className="App">

      <button onClick={onClicked()} />

    </div>
  );

  async function onClicked() {

    // Enter your storage account name and shared key
    const account = "REMOVED_MY_ACCOUNT";
    const accountKey = "REMOVED_ACCOUNT_KEY";

    // Use SharedKeyCredential with storage account and account key
    const sharedKeyCredential = new SharedKeyCredential(account, accountKey);

    // Use TokenCredential with OAuth token
    const tokenCredential = new TokenCredential("token");
    tokenCredential.token = "renewedToken"; // Renew the token by updating token field of token credential

    // Use AnonymousCredential when url already includes a SAS signature
    const anonymousCredential = new AnonymousCredential();

    // Use sharedKeyCredential, tokenCredential or anonymousCredential to create a pipeline
    const pipeline = StorageURL.newPipeline(sharedKeyCredential);

    // List containers
    const serviceURL = new ServiceURL(
      // When using AnonymousCredential, following url should include a valid SAS or support public access
      `https://${account}.blob.core.windows.net`,
      pipeline
    );

    // Create a container
    const containerName = `newcontainer${new Date().getTime()}`;
    const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);

    const createContainerResponse = await containerURL.create(Aborter.none);
    console.log(
      `Create container ${containerName} successfully`,
      createContainerResponse.requestId
    );

    // Create a blob
    const content = "hello";
    const blobName = "newblob" + new Date().getTime();
    const blobURL = BlobURL.fromContainerURL(containerURL, blobName);
    const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL);
    const uploadBlobResponse = await blockBlobURL.upload(
      Aborter.none,
      content,
      content.length
    );
    console.log(
      `Upload block blob ${blobName} successfully`,
      uploadBlobResponse.requestId
    );

  }
}

export default App;

Редактировать: я вызывал неправильный API.Вы можете создать новый проект Visual Studio, который использует шаблон .Net / React.Это был пример кода, который я искал.

1 Ответ

2 голосов
/ 13 июня 2019

Я разработчик хранилища JS SDK.SharedKeyCredential доступно только во время выполнения Node.js.Для браузеров, в целях безопасности, пожалуйста, используйте Shared Access Signature (SAS) или OAuth Token для вашей аутентификации.

...