import {  View as ViewFile} from '@/api/SafetyRule';
const Handler_DownLoadFile = (Id:number,IsEnglish:boolean)=>{
sfParam.Id=Id;
sfParam.IsEnglish=IsEnglish;
setSFParam(sfParam);
console.log(JSON.stringify(sfParam))
ViewFile(sfParam as SafetyRuleParamPO)
.then((res)=>{
if (res.StatusCode == 200 && res.Data){
if(res.Data.FileContent!=undefined){
const blob = UtilFile.ConvertBase64UrlToBlob(res.Data.FileContent);
const url = window.URL.createObjectURL(
new Blob([blob],{type:'application/pdf'})
);
const link = document.createElement('a');
link.href = url;
link.setAttribute(
'download',
"FileName.pdf",
);
// Append to html link element page
document.body.appendChild(link);
// Start download
link.click();
window.URL.revokeObjectURL(url);
}
}else{
alert("error")
}
})
}
export function  ConvertBase64UrlToBlob(base64Data):Blob {
const byteCharacters = atob(base64Data);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], {type: 'application/pdf'});
return blob;
}
import Request from '@/api/request';
import ApiResponsePO from "@/model/ResponseDTO/ApiResponseDTO"; import SafetyRuleViewPO from '@/model/PO/SafetyRuleViewPO' const http = new Request(); export const urlViewFile = '/api/SafetyRule/View​' export const View = (params: SafetyRuleParamPO): Promise<ApiResponsePO<SafetyRuleViewPO>> => {
return http.get<object, ApiResponsePO<SafetyRuleViewPO>>(urlViewFile,params);
}

recommen a :base64 to blob Code Example (codegrepper.com)

backend

        public SafetyRuleViewVO ReadFile(int Id,bool IsEnglish) {
var safetyVO = GetById(Id);
var viewVO = new SafetyRuleViewVO();
if (safetyVO != null) {
string filePath = IsEnglish ? safetyVO.EnglishVersionFileSharePointPath : safetyVO.ChineseVersionFileSharePointPath;
byte[] fileContent = File.ReadAllBytes(filePath);
viewVO = new SafetyRuleViewVO {
FileContent = fileContent
};
}
return viewVO;
}
 public class SafetyRuleViewVO {
public byte[] FileContent { get; set; }
}

最新文章

  1. CodingLife主题更新
  2. 关于调整浏览器窗口JS
  3. OJ-上海交大-1021. 从前有座山
  4. 关于ztree异步加载的问题(二)
  5. python中使用list作为默认参数且调用时不给其赋值的问题
  6. 感受函数式编程-scala
  7. 如何打开&ldquo;USB调试&rdquo;模式?
  8. linux 定时任务计划
  9. Linux下服务器环境的搭建和配置之一——Apache篇
  10. 转:检查点(web_reg_find函数详解)
  11. 【批处理学习笔记】第十二课:常用DOS命令(2)
  12. 腾讯云服务器php+mysq+nginx配置出现的问题及解决方法(亲测)
  13. javascript alert乱码的解决方法
  14. Spring Boot(十)Logback和Log4j2集成与日志发展史
  15. ps常用指令集
  16. group by分组后获得每组中符合条件的那条记录
  17. docker资料---仓库搭建
  18. SpringBoot文件上传下载
  19. yum安装mysql-5.6(centos7)
  20. 出现Unable to locate appropriate constructor on class 错误可能的原因

热门文章

  1. UE4笔记索引
  2. Lucky Chains(最大公约数的应用)
  3. API的风格
  4. docker指令 —— MySQL一条龙服务
  5. &lt;input&gt;输入框,限制输入的为正整数
  6. 使用async实现多个请求并发
  7. 可收集ALC问题[Microsoft.Data.SqlClient is not supported on this platform.]
  8. 【笔记】IDEA中maven导入依赖提示证书错误解决方法
  9. 读后笔记 -- Java核心技术(第11版 卷 II) Chapter2 输入与输出
  10. QueryDet: Cascaded Sparse Query for Accelerating High-Resolution Small Object Detection(QueryDet:用于加速高分辨率小目标检测的级联稀疏查询)