使用React将映像上传到Azure Blob存储

时间:2019-10-28 17:17:40

标签: reactjs azure-blob-storage

我想使用React将图像上传到Azure Blob存储。

我尝试了很多示例,但都没有用。

看似最好的是this one,但仍然无法使其在React上正常工作。

我现在正在尝试使用createContainerIfNotExists方法只是为了测试,错误是Cannot read property createBlobServiceWithSas of undefined

我的代码如下:

import AzureStorage from 'azure-storage';

const account = {
  name: 'x',
  sas: 'x',
};

const blobUri = `https://${account.name}.blob.core.windows.net`;
const blobService = AzureStorage.Blob.createBlobServiceWithSas(blobUri, account.sas);

export const createContainer = () => {
  blobService.createContainerIfNotExists('test', (error, container) => {
    if (error) {
      // Handle create container error
    } else {
      console.log(container.name);
    }
  });
};

export default createContainer;

1 个答案:

答案 0 :(得分:1)

根据我的研究,因为您开发了React应用程序,所以我们不能使用createBlockBlobFromBrowserFile方法。我们只是可以在浏览器中使用该方法。有关更多详细信息,请参阅documententer image description here

根据情况,建议您使用其他方法(例如uploadStreamToBlockBlob)以V10 sdk上传图像。有关更多详细信息,请参阅https://docs.microsoft.com/en-us/javascript/api/@azure/storage-blob/?view=azure-node-latest

相关问题