从服务器读取图片并显示到前端,C# 如何把后台获取的图片传递到前端并显示?...

本文介绍如何使用C#从服务器读取图片并将其传递到前端进行显示。通过Server.MapPath转换服务器路径,结合HttpFileCollection处理上传文件,检查文件类型和大小,并保存到服务器。最后返回图片URL供前端展示。
摘要由CSDN通过智能技术生成

@听风2008: 有个方法是将绝对路径转到服务器路径。Server.MapPath(upPath) 这个方法就是把你那个路径变成服务器路径。var domain = System.Configuration.ConfigurationManager.AppSettings["Domain"];

HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;

string upFileType = "|image/bmp|image/x-png|image/pjpeg|image/gif|image/png|image/jpeg|";

int upLength = 5;

string imgPath = "";

string upPath = "/upload/"; //上传文件路径

if (hfc.Count > 0)

{

string fileContentType = hfc[0].ContentType; //文件类型

if (upFileType.IndexOf(fileContentType.ToLower()) > 0)

{

string name = hfc[0].FileName; // 客户端文件路径

FileInfo file = new FileInfo(name);

string fileName = name.Substring(0, name.IndexOf(file.Extension)) + "_" + DateTime.Now.ToString("yyyyMMddhhmmssfff") + file.Exten

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值