c#处理前端传输二进制图片数据上传保存

public ActionResult UpLoad()

{

//1.0得到上传过来的文件

HttpFileCollectionBase fils = Request.Files;//得到上传过来的文件

if (fils.Count > 0)

{

//文件字节长度

if (fils[0].ContentLength > 0)

{

//2.0上传图片或要将图片的名称做一个修改(不能重复)

string oldName = fils[0].FileName;

//得到当前文件名称后缀

string exName = Path.GetFileName(oldName);

//生成一个永不重复的名称

string newName = Guid.NewGuid() + exName;

using (System.Drawing.Image img = System.Drawing.Image.FromStream(fils[0].InputStream))

{

img.Save(Server.MapPath("/img/") + newName);

return Content("OK");

}

}

else

{

//上传失败

return Content("ON");

}

}

else

{

//未选择数据

return Content("未选择数据");

}

}

相关推荐
曼巴UE54 小时前
UE FString, FName ,FText 三者转换,再次学习,官方文档理解
服务器·前端·javascript
行走的陀螺仪5 小时前
高级前端 Input 公共组件设计方案(Vue3 + TypeScript)
前端·javascript·typescript·vue·组件设计方案
一颗不甘坠落的流星5 小时前
【Antd】基于 Upload 组件,导入Json文件并转换为Json数据
前端·javascript·json
LYFlied5 小时前
Vue2 与 Vue3 虚拟DOM更新原理深度解析
前端·javascript·vue.js·虚拟dom
Lucky_Turtle6 小时前
【Node】npm install报错npm error Cannot read properties of null (reading ‘matches‘)
前端·npm·node.js
小飞侠在吗6 小时前
vue shallowRef 与 shallowReacitive
前端·javascript·vue.js
c#上位机6 小时前
halcon刚性变换(平移+旋转)——vector_to_rigid
图像处理·人工智能·计算机视觉·c#·halcon
Miss_SQ6 小时前
Webgl打包后删除StreamingAssets文件夹下多余资源
unity·c#·webgl
小猪快跑爱摄影6 小时前
【AutoCad 2025】【C#】零基础教程(二)——遍历 Entity 插件 =》 AutoCAD 核心对象层级结构
开发语言·c#·autocad