当前位置:网站首页>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");
}
}
边栏推荐
- LVS负载均衡群集及NAT模式群集
- Web optimization experience (6) - optimization closed-loop practice
- IR(红外遥控)基本原理
- HMS Core分析服务智能运营6.5.1版本上线
- Forward Propagation and Back Propagation
- [Deep Learning] Curriculum Learning
- docker部署redis容器问题
- 字节与字符与常见编码方式
- 2.5W 字详解线程与锁了,面试随便问!!
- Practical Case: Building Churn Prediction Models with PySpark ML
猜你喜欢
随机推荐
To make people's consumption safer, more assured and more satisfied
移动端/嵌入式-CV模型-2019:MobelNets-v3
MySQL redo log和undo log
PCBA电路板为什么需要使用三防漆,有何作用?
【收藏】3. 壁纸收藏
Feign应用及源码剖析
FreeSql 将 Saas 租户方案精简到极致[.NET ORM SAAS]
What is intrinsic safety?
Recommend 100 nice English songs
go web之响应用户
文档数据库于键值数据库有什么不同吗?
shell脚本知识记录
vs2019+boost库(boost_1_67_0)安装
Bytes and Characters and Common Encodings
Excel method is commonly used in text function 5
English token preprocessing, used to process English sentences into words
Multi-scalar multiplication: state of the art & new ideas
mysql-cdc 换2.2.x 版本 怎么读不到 数据 咋回事
正向传播和反向传播
hdu4635 Strongly connected(tarjan计算强连通通分量+缩点+思想)