当前位置:网站首页>C# api 将base64编码 上传至fastdfs转成文件
C# api 将base64编码 上传至fastdfs转成文件
2022-08-08 10:01:00 【饮水思源09】
/// <summary>
/// 上传缩略图base64
/// </summary>
/// <param name="image_body"></param>
/// <returns></returns>
[HttpPost]
[Route("UploadBase64Code")]
public ActionResult<IEnumerable<string>> UploadToServer([FromBody]ImageUploadBody image_body)
{
byte[] arr = Convert.FromBase64String(image_body.image.Split(',')[1]);
MemoryStream st = new MemoryStream(arr);
var storageNode = FastDFSInit.GetStorageNode();
string type = "jpg";
byte[] content = null;
using (BinaryReader reader = new BinaryReader(st))
{
content = reader.ReadBytes((int)st.Length);
}
string filePath = FastDFSClient.UploadFile(storageNode, content, type); //返回fastdfs文件路径
return Ok(new
{
status = true,
FilePath = filePath,
msg = "上传成功!"
});
}
public class ImageUploadBody
{
public string name;
public string image;
}
// fastdfs文件
public class FastDFSInit
{
public static StorageNode GetStorageNode()
{
//===========================初始化========================================
var trackerIPs = new List<IPEndPoint>();
// 只能指定IP,设置域名需要其他方式作为转换
string IP = FileAddress.GetFileServerAddress().ToString();
var endPoint = new IPEndPoint(IPAddress.Parse(IP), 22122);
trackerIPs.Add(endPoint);
ConnectionManager.Initialize(trackerIPs);
return FastDFSClient.GetStorageNode("group1");
}
}
边栏推荐
- 高并发下秒杀商品,你必须知道的9个细节
- COMSOL Multiphysics 6.0 software installation package and installation tutorial
- Mysql数据库架构介绍
- 重载与重写有什么区别?
- STL underlying implementation principle
- 让百姓消费更安全更放心更满意 江苏出台放心消费创建示范认定管理办法
- Detailed Explanation of Gradient Vanishing and Gradient Explosion Problems
- 利用图像二维熵实现视频信号丢失检测(Signal Loss Detection)
- 2万字50张图玩转Flink面试体系
- 各种attention的代码实现
猜你喜欢
随机推荐
数据库不推荐使用外键的9个理由!
22-08-06 Xi'an EasyExcel implements dictionary table import and export
VPP源地址NAT
SVN基本操作--文字解析版
牛客收藏上万的神作!这份阿里P8手写的MySQL主从原理手册真的牛
小散量化炒股记|打包Py可执行文件,双击就能选出全市场稳步上扬的股票
Elasticseach实践1
go web之响应用户
Mobile/Embedded-CV Model-2017: MobelNets-v1
xgboost 加速
2022世界机器人大会即将举办,智能机器人助推传统行业向智能化、数字化转型升级
梯度消失和梯度爆炸问题详解
小白求助,关于Go编译的顺序
Multi-scalar multiplication: state of the art & new ideas
VMWare Esxi 虚拟系统数据存储扩容(增加容量)的简明教程
A small test of basic grammar, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, basic grammar of go lang and the use of variables EP02
【图像分类】2022-MaxViT ECCV
Flutter 游戏教程之使用 Flutter 和 Flame 重现著名的 T-Rex 游戏
Recommend 100 nice English songs
文档数据库于键值数据库有什么不同吗?