angular - 如何从asp.net核心下载带有角度的fileStream
问题描述
大家好,我想下载 angular 7 的文件,我的后端是 .net 核心,这是我的后端代码:
[HttpPost]
public FileStream DownloadPack([FromBody]string gridplusSelectedData)
{
try
{
var updateData = JsonConvert.DeserializeObject<UpgradeViewModel>(gridplusSelectedData);
var getdateofGettingFiles = DateTime.Now.GetHashCode();
var selectedPPatch = @"G:\PackTemp\" + getdateofGettingFiles;
var mngfile = new CreatePatchCustomForCustomer();
var result = mngfile.CreatePatchFolder(updateData.GeneralInformation.GeneralStatus, updateData.GeneralInformation.AllDependencies, updateData.GeneralInformation.PriorityList, selectedPPatch);
// return new File(result, System.Net.Mime.MediaTypeNames.Application.Octet, "PatchDirectory.zip") ;
// return File(result, System.Net.Mime.MediaTypeNames.Application.Zip , "PatchDirectory.zip");
return new FileStream(result, FileMode.Open, FileAccess.Read);
}
catch (Exception ex)
{
return null;
}
}
这是我的前端代码
public downloadPatch() {
let previousData = this.configService.finalObjForDownloadPack
this.configService.post("PackPatchManager/DownloadPack", previousData,"zip").subscribe(blob => {
saveAs(blob, 'PatchDirectory.zip', {
type: 'text/plain;charset=windows-1252' // --> or whatever you need here
});
});
}
here is my front end Service
public post(url, body, mode?): Observable<any> {
let httpOptions
if (mode == "zip") {
httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json', 'responseType': 'blob' })
}
}
else {
httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
}
}
return this.http.post(this.serverAdress + url, body, httpOptions);
}
我的http post请求出错而不是成功
解决方案
推荐阅读
- gradle - 如何解决安装 warp10-ext-influxdb 插件时的 gradle shadowJar 问题?
- javascript - 只允许输入文本框中的数字
- python - Seaborn violinplot 中 HUE 参数的多列
- java - 线程“主”java.lang.UnsupportedClassVersionError 中的异常:
- javascript - React Hook useEffect 缺少对象的依赖项
- python - 我如何使用 python 文件从 localhost 上线???它不像其他普通的 html php 文件那样工作
- python - 只有 size-1 的数组可以转换为 Python 标量 python
- linux - 打印/查找非空字符串中的第一个字符(出现最低的字符)并且顺序很重要
- amazon-web-services - AWS.config.credentials.get() 花费太多时间
- c++ - 用于频繁分配和释放的基于轻树的数据结构的内存分配器