【发布时间】:2020-07-30 08:02:56
【问题描述】:
我正在尝试通过 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()
我尝试调用 stream 或 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)
最后一行返回undefined
使用有效的修改代码进行编辑:
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)
});
}
如何获取文件内容?
【问题讨论】:
-
根据文档
file.blobBody是一个承诺。您是否尝试过兑现承诺? -
@GauravMantri 成功了,谢谢。如果您想发布解决方案,很乐意回来查看并给您信用
标签: javascript reactjs azure azure-storage azure-storage-files