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 ...
随机推荐
- go+redis实现消息队列发布与订阅
在做项目过程中,实现websocket得时候,不知道哪里写的不太合适,客户端消息收到一定程度,剩下的消息收不到,修改了缓冲区大小,还是没有解决问题,后面因为项目结束期比较紧张,没有时间调试消息的时候, ...
- LP1-5:流程与沟通
口头沟通,整理归档,落到文档或JIRA任务中 JIRA上的需求有对应任务,开发任务对应需求任务号,测试任务号对应开发任务,上线任务对应测试及开发任务. 需求说明 :每个版本有什么功能. 控制需求三要素 ...
- SVG 从入门到后悔,怎么不早点学起来(图解版)
点赞 + 关注 + 收藏 = 学会了 作为一只前端,只懂 Vue.React 感觉已经和大家拉不开距离了. 可视化.机器学习等领域 JS 都有涉及到,而可视化方面已经被很多领域用到,比如大屏项目. 可 ...
- LogAgent —— etcd+kafka+zookeeper+go实现实时读取日志发送到kafka,并实现热加载配置读取的日志路径
工具包目录结构: .├── conf│ ├── logAgent.ini│ └── logAgentConfig.go├── etcd│ └── etcd.go├── kafka│ └ ...
- 【转】【善用佳软】文件复制软件评测:FastCopy、TeraCopy、ExtremeCopy、Supercopier
文件复制软件评测:FastCopy.TeraCopy.ExtremeCopy.Supercopier 原文:https://xbeta.info/fastcopy-teracopy-extremeco ...
- Bert使用
首先打开网址:https://huggingface.co/models 下载想用的模型
- [Docker-1自顶向下学习Docker
本文目录: 什么是DOCKER? 什么是容器? 什么是DOCKER镜像? DOCKER有什么使用场景和优势? 流程图一:从中央仓库拉取镜像并部署 流程图二:上传镜像到中央私库 结语 什么是DOCK ...
- 关于MYSQL知识点复习
关于MYSQL关联查询JOIN: https://www.cnblogs.com/withscorpion/p/9454490.html
- 浅谈AD域
活动目录(Active Directory)是面向Windows Standard Server.Windows Enterprise Server以及 Windows Datacenter Serv ...
- java开发常用软件下载
1.idea工具下载:https://www.jetbrains.com/idea/download/#section=windows 2.dbeaver下载:https://dbeaver.io ...