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; }
}

react backend and frontend download file的更多相关文章

  1. yii2自带的backend,frontend不够用,添加一个后台模块怎么做?

    在复杂项目里,高级模板中的fontend.backend application明显不够,可以再添加另外的application. 例如添加一个seller application .步骤如下: 1, ...

  2. Csharp:WebClient and WebRequest use http download file

    //Csharp:WebClient and WebRequest use http download file //20140318 塗聚文收錄 string filePath = "20 ...

  3. Pattern: API Gateway / Backend for Front-End

    http://microservices.io/patterns/apigateway.html Pattern: API Gateway / Backend for Front-End Contex ...

  4. 抽取一部分服务端做BFF(Backend For Frontend服务于前端的后端)

    Flutter+Serverless端到端研发架构实践 · 语雀 https://www.yuque.com/xytech/flutter/kdk9xc 2019-12-19 13:14 作者:闲鱼技 ...

  5. [Powershell] FTP Download File

    # Config $today = Get-Date -UFormat "%Y%m%d" $LogFilePath = "d:\ftpLog_$today.txt&quo ...

  6. FTP Download File By Some Order List

    @Echo Off REM -- Define File Filter, i.e. files with extension .RBSet FindStrArgs=/E /C:".asp&q ...

  7. Download file using libcurl in C/C++

    http://stackoverflow.com/questions/1636333/download-file-using-libcurl-in-c-c #include <stdio.h&g ...

  8. httpClient download file(爬虫)

    package com.opensource.httpclient.bfs; import java.io.DataOutputStream; import java.io.File; import ...

  9. Spring boot download file

    Springboot对资源的描述提供了相应的接口,其主要实现类有ClassPathResource.FileSystemResource.UrlResource.ByteArrayResource. ...

  10. Springboot Download file

    @RequestMapping(value = "/downloadSvt") public ResponseEntity<FileSystemResource> ex ...

随机推荐

  1. tasklist

    tasklist是windows下列出进程信息的指令,可配合taskKill来关毕进程 https://learn.microsoft.com/zh-cn/windows-server/adminis ...

  2. .NetCore2.0引用DLL报System.InvalidOperationException: Can not find compilation library location for package 'XXX'

    .NET CORE 2.0 MVC项目引用类库出现:System.InvalidOperationException: Can not find compilation library locatio ...

  3. LinuxK8S集群搭建二(Node节点部署)

    系统环境: CentOS 7 64位 准备工作: 通过虚拟机创建三台CentOS服务器,可参照之前的文章:Windows10使用VMware安装centos192.168.28.128 --maste ...

  4. [CSS]背景图片很大,根据屏幕缩小适配后,div之间有空隙的问题

    RT.美术给的素材宽度是1080px的. 在不缩放的情况下,1080px宽度的屏幕显示div之间正常,没有空隙,但使用transform属性之后,div缩小,div之间有空隙(白线) 百度有人说给这些 ...

  5. 浅谈spark

    spark spark是一个开源分布式计算框架,在于让计算更加快速,通常使用资源调度器yarn和spark自带的资源调度器standalond进行调度,spark相对于Hadoop更加快速,基于它是内 ...

  6. npm 局部安装 jbrowse

    #此处不要加 -g参数 , -g 是全局安装 npm install @jbrowse/cli #用npx 才能使用这个包,无法按照官方文档直接使用 npx jbrowse --version

  7. 文件下载,后端接口,django,flask

    Django后端接口 def download_excel(request): """ get excel file from url param and upload ...

  8. Selenium无浏览器页面执行测试用例—静默执行

    在执行WebUI自动化用例的时候,经常需要不打开浏览器执行自动化测试,这时就需要用到浏览器的静默执行.浏览器静默执行要点:1.定义Chrome的选项,两种方式任选 chrome_options = w ...

  9. 【PDF】日本流行文化中的中国经典巨著:《三国志》与《三国演义》 | 陈曦子 |

    书本详情 标题:日本流行文化中的中国经典巨著:<三国志>与<三国演义> | 陈曦子 |年份:2019出版社:暨南大学出版社ISBN10:7566828355ISBN13:978 ...

  10. Window10上CLion极简配置教程

    Window10上CLion极简配置教程 1. 首先,下载安装CLion 去JB公司官网下载CLion,https://www.jetbrains.com/clion/download/#sectio ...