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. C++用递归实现求解相关函数

    //递归实现Hanoi塔问题#include<iostream>#include<cstdlib>using namespace std;#define MAXSIZE 100 ...

  2. vue的:class设置多个值

    vue的:class设置多个值 :class="[{ 'labTilTemplate': item.editType == 11 }, { 'txtBold': item.bold == 1 ...

  3. iOS组件化 pod命令创建私有库详解【引用其他私有库、oc、Swift混编】

    1.命令创建pod pod lib create pod的名字 2.根据指令依次填写信息 3.填写完成后会自动打开项目 .然后修改podspec文件即可 4.创建当前pod的git 仓库.将当前代码放 ...

  4. byte最高位

    /** * 将byte转换为一个长度为8的byte数组,数组每个值代表bit */public static byte[] replaceSpace(Byte b){ byte[] array=new ...

  5. js数组去重,删除重复的属性值

    let a=[] let hash={} a=a.reduce((pre,next)=>{ hash[next.name]?"":(hash[next.name]=true& ...

  6. C#笔记誊录

    1.继承 面向对象的三大特征: 封装性 继承性  多态性 一.继承:类与类的关系 为什么会用继承:减少代码重复 优化 空间内存 实现多态 class 基类 { //基类成员 } class 子类:基类 ...

  7. OM6621P系列国产M4F内核低功耗BLE5.1 SoC蓝牙芯片

    随着5G与物联网时代到来,智慧城市.电动出行.智能家居.可穿戴设备等应用高速发展,低功耗蓝牙技术在近几年智能化浪潮中的地位也尤为重要.OM6621P系列的开发即是为解决国内低功耗蓝牙应用设计需求,其主 ...

  8. linux下进程通信总结

    信号: 信号是通知发生了某种事件的机制,内核和进程都可能会向进程发送各种信号,进程也可以向自己发送信号.系统定义了一组标准信号类型,每种信号都拥有唯一的数值和用途.典型的信号递送是异步的,意味着进程可 ...

  9. php集成环境包PhpStudy及部署网站

    一.介绍:  phpStudy 是一个PHP调试环境的程序集成包. 该程序包集成最新的Apache+PHP+MySQL+phpMyAdmin+ZendOptimizer,一次性安装,无须配置即可使用, ...

  10. SPI主机Verilog代码实现

    前面已经提到过了SPI,在SPI从机的设计中已经讲过SPI的基本原理,这里就不再赘述.对于SPI的主机可以参考百度百科或则笔者前面写的SPI从机介绍的相关知识. 下面是SPI_master的代码 SP ...