asp.net图片上传,图片尺寸为2000:600(504kb),上传到服务器后变成了1600:480(62kb),百度后得出结果为要修改iis配置,修改后,通过input file上传的图片尺寸正常,但是通过js的webuploader上传,上传后的尺寸任然为1600:480,调试js发现,在js里获取的文件大小是正常,vs调试,ashx里面获取的图片大小改变了,求解
这段为input file 上传图片的后台代码
protected void btnUpload_Click(object sender, EventArgs e)
{
HttpFileCollection Files = HttpContext.Current.Request.Files;
for (int i = 0; i < Files.Count; i++)
{
HttpPostedFile PostedFile = Files[i];
if (PostedFile.ContentLength > 0)
{
string FileName = PostedFile.FileName;
string strExPrentFile = FileName.Substring(FileName.LastIndexOf(".") + 1);
string sFilePath = "a.jpg";
PostedFile.SaveAs(Server.MapPath(sFilePath));
}
else
{
}
}
}
这段为webuploader上传图片的后台代码
private void UpLoadFile(HttpContext context, string strUrl, string strToUrl,string userID)
{
Dsxy.Model.siteconfig siteConfig = new Dsxy.BLL.siteconfig().loadConfig();
string _delfile = DTRequest.GetString("DelFilePath");
HttpPostedFile _upfile = context.Request.Files["Filedata"];
bool _iswater = false; //默认不打水印
bool _isthumbnail = false; //默认不生成缩略图
if (DTRequest.GetQueryString("IsWater") == "1")
_iswater = true;
if (DTRequest.GetQueryString("IsThumbnail") == "1")
_isthumbnail = true;
if (_upfile == null)
{
context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}");
return;
}
UpLoad upFiles = new UpLoad();
string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, strUrl, strToUrl,userID);
//删除已存在的旧文件,旧文件不为空且应是上传文件,防止跨目录删除
if (!string.IsNullOrEmpty(_delfile) && _delfile.IndexOf("../") == -1
&& _delfile.ToLower().StartsWith(siteConfig.webpath.ToLower() + siteConfig.filepath.ToLower()))
{
Utils.DeleteUpFile(_delfile);
}
//返回成功信息
context.Response.Write(msg);
context.Response.End();
}
/// <summary>
/// 文件上传方法
/// </summary>
/// <param name="postedFile">文件流</param>
/// <param name="isThumbnail">是否生成缩略图</param>
/// <param name="isWater">是否打水印</param>
/// <returns>上传后文件信息</returns>
public string fileSaveAs(HttpPostedFile postedFile, bool isThumbnail, bool isWater,string strUrl=null,string strToUrl=null,string userID=null)
{
Dsxy.Model.siteconfig siteConfig = new Dsxy.BLL.siteconfig().loadConfig();
try
{
string fileExt = Utils.GetFileExt(postedFile.FileName); //文件扩展名,不含“.”
int fileSize = postedFile.ContentLength; //获得文件大小,以字节为单位
string fileName = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf(@"\") + 1); //取得原文件名
string newFileName = Utils.GetRamCode() + "." + fileExt; //随机生成新的文件名
//string newFileName = userID + "." + fileExt; //根据ID生成新的文件名
string newThumbnailFileName = "thumb_" + newFileName; //随机生成缩略图文件名
//string upLoadPath = GetUpLoadPath(); //上传目录相对路径
string upLoadPath = strToUrl; //上传目录相对路径
string fullUpLoadPath = AppDomain.CurrentDomain.BaseDirectory + upLoadPath;
//try
//{
// fullUpLoadPath = Utils.GetMapPath(upLoadPath); //上传目录的物理路径
//}
//catch (Exception)
//{
// fullUpLoadPath = AppDomain.CurrentDomain.BaseDirectory + upLoadPath;
//}
string newFilePath = upLoadPath + newFileName; //上传后的路径
string newThumbnailPath = upLoadPath + newThumbnailFileName; //上传后的缩略图路径
//检查文件扩展名是否合法
if (!CheckFileExt(fileExt))
{
return "{\"status\": 0, \"msg\": \"不允许上传" + fileExt + "类型的文件!\"}";
}
//检查文件大小是否合法
if (!CheckFileSize(fileExt, fileSize))
{
return "{\"status\": 0, \"msg\": \"文件超过限制的大小!\"}";
}
//检查上传的物理路径是否存在,不存在则创建
if (!Directory.Exists(fullUpLoadPath))
{
Directory.CreateDirectory(fullUpLoadPath);
}
//保存文件
postedFile.SaveAs(fullUpLoadPath + newFileName);
//如果是图片,检查图片是否超出最大尺寸,是则裁剪
if (IsImage(fileExt) && (this.siteConfig.imgmaxheight > 0 || this.siteConfig.imgmaxwidth > 0))
{
Thumbnail.MakeThumbnailImage(fullUpLoadPath + newFileName, fullUpLoadPath + newFileName,
this.siteConfig.imgmaxwidth, this.siteConfig.imgmaxheight);
}
//如果是图片,检查是否需要生成缩略图,是则生成
if (IsImage(fileExt) && isThumbnail && this.siteConfig.thumbnailwidth > 0 && this.siteConfig.thumbnailheight > 0)
{
Thumbnail.MakeThumbnailImage(fullUpLoadPath + newFileName, fullUpLoadPath + newThumbnailFileName,
this.siteConfig.thumbnailwidth, this.siteConfig.thumbnailheight, "Cut");
}
else
{
newThumbnailPath = newFilePath; //不生成缩略图则返回原图
}
//如果是图片,检查是否需要打水印
if (IsWaterMark(fileExt) && isWater)
{
switch (this.siteConfig.watermarktype)
{
case 1:
WaterMark.AddImageSignText(newFilePath, newFilePath,
this.siteConfig.watermarktext, this.siteConfig.watermarkposition,
this.siteConfig.watermarkimgquality, this.siteConfig.watermarkfont, this.siteConfig.watermarkfontsize);
break;
case 2:
WaterMark.AddImageSignPic(newFilePath, newFilePath,
this.siteConfig.watermarkpic, this.siteConfig.watermarkposition,
this.siteConfig.watermarkimgquality, this.siteConfig.watermarktransparency);
break;
}
}
//处理显示的地址
string imageUrl = siteConfig.imagespath;
newFilePath = imageUrl + strUrl + newFilePath.Substring(newFilePath.LastIndexOf("/") + 1);
newThumbnailPath = imageUrl + strUrl + newThumbnailPath.Substring(newThumbnailPath.LastIndexOf("/") + 1);
//处理完毕,返回JOSN格式的文件信息
return "{\"status\": 1, \"msg\": \"上传文件成功!\", \"name\": \""
+ fileName + "\", \"path\": \"" + newFilePath + "\", \"thumb\": \""
+ newThumbnailPath + "\", \"size\": " + fileSize + ", \"ext\": \"" + fileExt + "\"}";
}
catch
{
return "{\"status\": 0, \"msg\": \"上传过程中发生意外错误!\"}";
}
}
都是以http流来接收图片的,是什么原因呢,求解