我正在尝试通过 React 应用程序从 azure 文件共享下载文件 我连接良好,制作一个文件客户端并使用 this method 下载它
没有太多的文档,所以我正在尝试导航 promise 以获取文件内容来下载它们 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)
最后一行返回未定义
使用有效的更改代码进行编辑:
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 }
一旦你兑现了这个 promise ,你应该得到Blob
。
关于javascript - 尝试通过React应用程序从 azure 文件共享下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61261131/