react backend and frontend download file
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的更多相关文章
- yii2自带的backend,frontend不够用,添加一个后台模块怎么做?
在复杂项目里,高级模板中的fontend.backend application明显不够,可以再添加另外的application. 例如添加一个seller application .步骤如下: 1, ...
- Csharp:WebClient and WebRequest use http download file
//Csharp:WebClient and WebRequest use http download file //20140318 塗聚文收錄 string filePath = "20 ...
- Pattern: API Gateway / Backend for Front-End
http://microservices.io/patterns/apigateway.html Pattern: API Gateway / Backend for Front-End Contex ...
- 抽取一部分服务端做BFF(Backend For Frontend服务于前端的后端)
Flutter+Serverless端到端研发架构实践 · 语雀 https://www.yuque.com/xytech/flutter/kdk9xc 2019-12-19 13:14 作者:闲鱼技 ...
- [Powershell] FTP Download File
# Config $today = Get-Date -UFormat "%Y%m%d" $LogFilePath = "d:\ftpLog_$today.txt&quo ...
- FTP Download File By Some Order List
@Echo Off REM -- Define File Filter, i.e. files with extension .RBSet FindStrArgs=/E /C:".asp&q ...
- Download file using libcurl in C/C++
http://stackoverflow.com/questions/1636333/download-file-using-libcurl-in-c-c #include <stdio.h&g ...
- httpClient download file(爬虫)
package com.opensource.httpclient.bfs; import java.io.DataOutputStream; import java.io.File; import ...
- Spring boot download file
Springboot对资源的描述提供了相应的接口,其主要实现类有ClassPathResource.FileSystemResource.UrlResource.ByteArrayResource. ...
- Springboot Download file
@RequestMapping(value = "/downloadSvt") public ResponseEntity<FileSystemResource> ex ...
随机推荐
- Spring随意总结
Spring框架的优点 1.使用Spring的IOC容器,将对象之间的依赖关系交给Spring,降低组件之间的耦合性,让我们更专注于应用逻辑 2.可以提供众多服务,事务管理,WS等. 3.AOP的很好 ...
- oracle 行转列,动态年份,月份列。已解决!
-----------------存储过程包体----------- procedure GetComparativeAnalysisTB(p_StartTime varchar2, ----开始时间 ...
- Win10系统桌面exe文件图标消失不见了的解决方法
使用 Windows10正式版系统 过程中,发现桌面上的一些exe文件图标突然消失不见了.虽然这些exe程序还能够正常运行,可是感觉还是非常不舒服.这该怎么办呢?接下来,就随小编看看Windows10 ...
- 将【jar包、bat、其他文件】注册到windows服务的三种方法
将[jar包.bat.其他文件]注册到windows服务的三种方法 1.instsrv.exe和srvany.exe 1.下载配置instsrv和srvany 下载地址:https://dl.pcon ...
- Curl 命令举例
curl是一个强大的网络请求lib,虽然强大,但是参数太多哈,不得不吐槽,下面列举一下常用使用方法,供大家CV POST 请求 入门: curl -X POST "http://localh ...
- java中线程的两种创建方式
第一种:继承java.lang.Thread类.然后重写run方法 例如我们模拟一个龟兔赛跑 1 package edu.aeon.thread; 2 3 /** 4 * 说明:模拟龟兔赛跑 5 * ...
- WPF 使用Path(自定义控件,圆形进度条)
原文:https://www.cnblogs.com/tsliwei/p/5609035.html 原文链接:https://blog.csdn.net/johnsuna/article/detail ...
- Android GNSS模块详解
1. 参考https://blog.csdn.net/yang_mao_shan/category_12133410.html GNSS 架构是从 应用层 ---> 通过原生 jar 包 --- ...
- springboot启动报错 Failed to scan *****/derbyLocale_ja_JP.jar from classloader hierarchy
springboot启动报错 Failed to scan *****/derbyLocale_ja_JP.jar from classloader hierarchy 这两天自己在玩虚拟机,想把 ...
- GIS空间分析和建模复习重点4
27.三维地形分析的方法 常用的有 ·坡度分析 ·坡向分布 ·填挖方分析 ·山体阴影分析 ·通视分析 28.空间分析实际应用 (1)城市应急避难场所是城市防灾减灾规划的重要组成部分,应急避难场所的建设 ...