尝试通过 React 应用程序从 Azure 文件共享下载文件

trying to download a file from an azure file share via react app

我正在尝试通过 React 应用程序从 Azure 文件共享下载文件 我连接正常制作一个文件客户端并使用 this method

下载它

文档的方式不多,所以我正在努力兑现获取文件内容以下载它们的承诺 using this

我返回的对象在控制台日志记录的下方。

{
  "lastModified": "2020-04-09T21:01:45.000Z",
  "metadata": {},
  "contentType": "application/x-zip-compressed",
  "requestId": "xxx-401a-004e-193c-xxx",
  "version": "2019-07-07",
  "isServerEncrypted": true,
  "fileAttributes": "Archive",
  "fileCreatedOn": "2020-04-09T21:01:45.148Z",
  "fileLastWriteOn": "2020-04-09T21:01:45.148Z",
  "fileChangeOn": "2020-04-09T21:01:45.148Z",
  "filePermissionKey": "xxx*xxx",
  "fileId": "xxxxx",
  "fileParentId": "xxxxx",
  "leaseState": "available",
  "leaseStatus": "unlocked",
  "blobBody": {}
}

...

blobBody: Promise { "fulfilled" }
​​
<state>: "fulfilled"
​​
<value>: Blob
​​​
size: 1960118
​​​
type: "application/x-zip-compressed"
​​​
<prototype>: BlobPrototype
​​​​
arrayBuffer: function arrayBuffer()
​​​​
constructor: function ()
​​​​
size: 
​​​​
slice: function slice()
​​​​
stream: function stream()
​​​​
text: function text()

我尝试调用流或 arrayBuffer 函数,但我似乎无法访问 promise

中的任何内容
console.log(`downloading file: ${fileName}`)
const fileClient = this.state.doneDirClient.getFileClient(fileName)
const file = await fileClient.download()
console.log(file)
console.log(file.blobBody.Blob)

最后一行returnsundefined

使用修改过的有效代码进行编辑:

  async download(fileName: string) {
    const fileClient = this.state.doneDirClient.getFileClient(fileName)
    const file = await fileClient.download()
    Promise.resolve(file.blobBody).then(function (value) {
      fileDownload(value, fileName)
    });
  }

如何获取文件内容?

如果您查看 FileDownloadResponse 的定义,您会注意到 blobBody 参数本质上是一个 Promise

type FileDownloadResponse = FileDownloadHeaders & { _response: Object, blobBody: Promise<Blob>, readableStreamBody: NodeJS.ReadableStream }

一旦你解决了那个承诺,你应该得到 Blob