Blazor 从 URL 下载 Azure Blob
Blazor Download Azure Blob from URL
我有一个 Blazor“下载按钮”组件,它将从我的 API 获取一个 URI,其中包含 Azure Blob 存储中的一个 Blob 的绝对 URI。从 API 返回 URI 后,我调用一个 JS 函数来创建你看到的 href。单击 href 时,将打开文件而不是下载文件。有谁知道我做错了什么?
JS 代码:我在我的组件中使用 JS 隔离
export function Download(url, fileName) {
let a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
}
生成 href
<a href="https://myBlobStorage.blob.core.windows.net/filePath.txt?sv=sharedAccessToken" download="FileName.txt"></a>
谢谢,
特拉维斯佩特里
我最终使用 Blazor 库从服务器下载文件流。
图书馆:https://github.com/arivera12/BlazorDownloadFile
我将服务器更改为 return 文件响应:
return File(blob.DownloadStreaming().Value.Content, blob.GetProperties().Value.ContentType);
然后在 Blazor 中调用下载代码:
var resp = await _httpClient.GetAsync($"URL");
await BlazorDownloadFileService.DownloadFile("test.txt", await resp.Content.ReadAsByteArrayAsync(), resp.Content.Headers.ContentType.ToString());
我有一个 Blazor“下载按钮”组件,它将从我的 API 获取一个 URI,其中包含 Azure Blob 存储中的一个 Blob 的绝对 URI。从 API 返回 URI 后,我调用一个 JS 函数来创建你看到的 href。单击 href 时,将打开文件而不是下载文件。有谁知道我做错了什么?
JS 代码:我在我的组件中使用 JS 隔离
export function Download(url, fileName) {
let a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
}
生成 href
<a href="https://myBlobStorage.blob.core.windows.net/filePath.txt?sv=sharedAccessToken" download="FileName.txt"></a>
谢谢,
特拉维斯佩特里
我最终使用 Blazor 库从服务器下载文件流。
图书馆:https://github.com/arivera12/BlazorDownloadFile
我将服务器更改为 return 文件响应:
return File(blob.DownloadStreaming().Value.Content, blob.GetProperties().Value.ContentType);
然后在 Blazor 中调用下载代码:
var resp = await _httpClient.GetAsync($"URL");
await BlazorDownloadFileService.DownloadFile("test.txt", await resp.Content.ReadAsByteArrayAsync(), resp.Content.Headers.ContentType.ToString());