我正在我的WebAPI中生成一个Excel文件.我将它"存储"在一个内存流中,然后将响应输入如下:
var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(ms) };
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = projectName + ".xlsx"
};
// ms.Close();
return result;
Run Code Online (Sandbox Code Playgroud)
看起来服务器端工作正常.如果我将该内存流写入文件流,则会创建该文件,并且可以毫无问题地打开该文件.
在角度方面,如何在单击按钮时重新创建文件?
我试过这样的事情:
$scope.exportQuotas = function (projectName) {
homeService.GetQuotas(projectName, $routeParams.token, $scope.selection).then(
function (data) {
var dataUrl = 'data:application/octet-stream;' + data
var link = document.createElement('a');
angular.element(link)
.attr('href', dataUrl)
.attr('download', "bl.xlsx")
.attr('target', '_blank')
link.click();
})
}
Run Code Online (Sandbox Code Playgroud)
该文件已创建但当我尝试打开它时,它已损坏...我已尝试将数据类型更改为vnd.ms-excel in angular但它不起作用...我怎样才能获得该文件点击下载?
编辑 Jorg回答后,我尝试了以下内容:api返回的是:
Status Code: 200
Pragma: no-cache
Date: Tue, 02 Sep 2014 …Run Code Online (Sandbox Code Playgroud) 我正在启动一个个人项目,以了解实现微服务的最佳方法。它可能是过度设计的,但它更像是一个学习过程。这可能无关紧要,但我正在使用 .Net Core
我对设计解决方案的想法如下:
问题:
我正在尝试按照https://ocelot.readthedocs.io/en/latest/features/authentication.html使用 Ocelot 和 IS4
使用时
public void ConfigureServices(IServiceCollection services)
{
var authenticationProviderKey = "TestKey";
services.AddAuthentication()
.AddJwtBearer(authenticationProviderKey, x =>
{
});
}
Run Code Online (Sandbox Code Playgroud)
并在 ocelot.json 中使用“TestKey”,它在启动应用程序时抛出错误
无法启动 Ocelot,错误是:TestKey,AllowedScopes:[] is unsupported authentication provider
知道出了什么问题吗?我需要在我的 IdentityServer 应用程序中特别设置一些东西吗?
c# ×3
.net-core ×1
angularjs ×1
api-gateway ×1
excel ×1
nservicebus ×1
ocelot ×1
redis ×1
rest ×1