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 ...
随机推荐
- web上传插件Uploadify
Uploadify简单说来,是基于Jquery的一款文件上传插件.它的功能特色总结如下: 支持单文件或多文件上传,可控制并发上传的文件数 在服务器端支持各种语言与之配合使用,诸如PHP,.NET,Ja ...
- java读取虚拟串口数据
语言:java 虚拟串口工具:Virtual Serial Port Driver Pro 9.0,选择pairing模块下,点击add virtual paring按钮即可创建串口对,还无法自定义o ...
- C语言中static关键字用法
概述 static关键字在c语言中比较常用,使用恰当能够大大提高程序的模块化特性,有利于扩展和维护. 在程序中使用static 变量 1. 局部变量 普通局部变量是再熟悉不过的变量了,在任何一个函数内 ...
- 学习Typora免费安装步骤
学习Typora免费安装步骤 第一步: 安装typora-setup-x64-1.2.4.exe, 注意版本 第二步: 替换掉resources目录下的app.asar文件 第三步: 重启Typora ...
- c++练习266题:楼层编号
*266题 原题传送门:http://oj.tfls.net/p/266 题解: #include<bits/stdc++.h>using namespace std; int t;//高 ...
- web基础(3):CSS样式
chapter4 CSS样式 html是网页的内容和结构:CSS是网页的样式.内容和样式相分离,便于修改样式. CSS cascading style sheets 层叠样式表.一个内容上面可以添加多 ...
- nginx转发tomcat之https不生效
1.修改tomcat配置server.xml,让它从请求头中的X-Forwarded-Proto读取 <!-- xpath://Server/Service/Engine/Value --> ...
- 微服务笔记之Eureka03(服务注册分析)
服务注册接口源码分析: com.netflix.eureka.resources.ApplicationResource#addInstance public Response addInstance ...
- leetcode91解码
解码,dp,注意特殊情况 def numDecodings( s: str) -> int: if len(s) < 1: return 1 if s[0] =='0': return 0 ...
- Blog-3
前言 这几周的作业所涉及的知识点有数据的封装和.继承与多态.正则表达式,还有抽象类和接口,另外还有javafx的一些基本知识.题量适中,但是难度对于我来说是比较大的.总的来说就是跟以前的题目差不多,只 ...