【发布时间】:2021-04-19 18:52:48
【问题描述】:
我正在尝试检索在后端(弹簧启动)中生成的 .xlsx 文件。在前端,我检索标题,如您所见,其中包括 content-disposition。但我无法访问标题内容配置。
正如您在下面的打印中看到的那样,标头中不存在内容处置,而是存在于 XHR 响应标头中。 Xhr 响应 console.log
我在 backed 上启用 cors 策略,
public class WebSecurityConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
}
并在客户端获取内容配置
public static downloadFile(data: any, untilDestroyed$: DestroyService, toasterService?: ToastrService) {
const openInWindow = data.body.type === 'application/pdf';
console.log(data);
const dispositionHeader = data.headers.get('Content-Disposition'); // there is problem, value is not possible get
const blob = new Blob([data.body], {type: data.body.type});
const url = window.URL.createObjectURL(blob);
【问题讨论】:
标签: angular typescript spring-boot