.net上传大文件出现报错情况
前端flex调用后台上传程序,小文件上传没事,大文件上传出错
后台上传程序如下代码:
public class UploadHandler : IHttpHandler
{
private string uploadFolderPic = "Upload/pic";
private string uploadFolderMp4 = "Upload/mp4";
private int maxPostSize = 200 * 1024 * 2024;//设置文件的大小问200M
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string gcid = context.Request.QueryString["gcid"] == null ? "" : context.Request.QueryString["gcid"].ToString();
string type = context.Request.QueryString["type"] == null ? "" : context.Request.QueryString["type"].ToString();
//context.Response.Write("Hello World");
HttpFileCollection files = context.Request.Files;
if (files.Count > 0)
{
string path = "";
if (type == "pic")
path=context.Server.MapPath(uploadFolderPic);
else if (type == "mp4")
path = context.Server.MapPath(uploadFolderMp4);
HttpPostedFile file = files[0];
string folderPath=path+ "/" +gcid;
if (Directory.Exists(folderPath) == false)//如果不存在就创建file文件夹
{
Directory.CreateDirectory(folderPath);
}
if (file != null && file.ContentLength > 0)
{
string savePath = folderPath + "/" + context.Request.Form["fileName"];
file.SaveAs(savePath);
context.Response.Write("上传完成");
context.Response.End();
}
}
else
{
context.Response.Write("参数错误");
context.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
后台上传程序如下代码:
public class UploadHandler : IHttpHandler
{
private string uploadFolderPic = "Upload/pic";
private string uploadFolderMp4 = "Upload/mp4";
private int maxPostSize = 200 * 1024 * 2024;//设置文件的大小问200M
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string gcid = context.Request.QueryString["gcid"] == null ? "" : context.Request.QueryString["gcid"].ToString();
string type = context.Request.QueryString["type"] == null ? "" : context.Request.QueryString["type"].ToString();
//context.Response.Write("Hello World");
HttpFileCollection files = context.Request.Files;
if (files.Count > 0)
{
string path = "";
if (type == "pic")
path=context.Server.MapPath(uploadFolderPic);
else if (type == "mp4")
path = context.Server.MapPath(uploadFolderMp4);
HttpPostedFile file = files[0];
string folderPath=path+ "/" +gcid;
if (Directory.Exists(folderPath) == false)//如果不存在就创建file文件夹
{
Directory.CreateDirectory(folderPath);
}
if (file != null && file.ContentLength > 0)
{
string savePath = folderPath + "/" + context.Request.Form["fileName"];
file.SaveAs(savePath);
context.Response.Write("上传完成");
context.Response.End();
}
}
else
{
context.Response.Write("参数错误");
context.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
...全文
相关推荐
[Asp.net]Uploadify上传大文件,Http error 404 解决方案
在ASP.NET开发中,使用Uploadify插件进行大文件上传时,可能会遇到HTTP错误404的问题。
PHP fastcgi模式上传大文件(大约有300多K)报错
在PHP开发过程中,有时会遇到在FastCGI模式下上传大文件时出现错误的情况,这主要是由于服务器配置的限制导致的。
KindEditor3.5.1 asp.net 解决图片上传报错问题例子
该项目针对KindEditor 3.5.1在ASP.NET环境下图片上传报错的问题提供了解决方案示例。通过整合前端富文本编辑器与后端C#逻辑,实现了图片上传功能的调试与修复,并展示了如何正确配置编辑器
解决.net项目中上传的图片或者文件太大无法上传问题
通过调整这些参数,我们可以根据实际需求调整ASP.NET的性能和安全性设置,从而解决大文件上传问题。
UEditor(五)——解决上传图片时报错:未找到上传数据
服务器端需要有一个接收并处理这些数据的接口,这个接口通常是一个PHP、Java或.NET等后端语言编写的脚本。如果这个接口不存在或者配置有误,就会出现“未找到上传数据”的错误。


Web Services
