如何上传大文件2 GB或更多大小文件上传服务器文件夹在asp.net c# [英] How To Upload Big size file 2 GB Or more Size File upload in server Folder in asp.net c#

查看:131
本文介绍了如何上传大文件2 GB或更多大小文件上传服务器文件夹在asp.net c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器文件夹中有1 Gb视频文件上传,但生成错误



错误:



HTTP错误404.13 - 未找到

请求过滤模块配置为拒绝超过请求内容长度的请求。

最有可能原因:



请求过滤在Web服务器上配置为拒绝请求,因为内容长度超过了配置的值。



你做的事情可以尝试:



验证applicationhost.config或web.config文件中的configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength设置。



-------------------------------------- -----------------

i有以上错误相关搜索,所以有些解决方案给我喜欢



1)< httpruntime targetframework =4.5executiontimeout =90> maxrequestlength =4096>

useFullyQualifiedRedirectUrl =falseminFreeThreads =8

minLocalRequestFreeThreads =4

appRequestQueueLimit =100enableVersionHeader =true/>



2)< httpruntime executiontimeout =240maxrequestlength =20480>



------- -------------------------------------------------- ---------

以上解决方案我试过但没有解决这个错误,



请给我解决方案,我在服务器文件夹中有2 Gb或更大尺寸没有限制大小的文件上传给我快速解决方案(我认为多方类型解决但不知道如何解决..)

I have 1 Gb Video File Upload in my server folder ,But error generate

Error :

HTTP Error 404.13 - Not Found
The request filtering module is configured to deny a request that exceeds the request content length.
Most likely causes:

Request filtering is configured on the Web server to deny the request because the content length exceeds the configured value.

Things you can try:

Verify the configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength setting in the applicationhost.config or web.config file.

-------------------------------------------------------
i have Above error related Search , So some solution give me like as

1) <httpruntime targetframework="4.5" executiontimeout="90">maxrequestlength="4096">
useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100" enableVersionHeader="true" />

2)<httpruntime executiontimeout="240" maxrequestlength="20480">

------------------------------------------------------------------
Above Solution i have try but not solve this error,

Please Give me solution , i have 2 Gb Or More size no limit size file upload in server folder give me solution fast(i think multiparty type to solve but don't know how to solve ..)

推荐答案

问题是在你的web.config中你的文件默认大小设置为4mb(默认为4mb,所以即使没有设置设置,那么4mb大小将被定义为maxRequestSize属性的值的httpRuntime)。



对此的解决方案是,更改该值并更新它以使其成为您自己的选择。



以下显示了一个示例,您绝对可以添加更多属性来在IIS中创建(或维护或更新)您的网站配置。



The problem is that inside your web.config your default size for the file is set to be 4mb (4mb is default, so even if there is no settings set then 4mb size would be define as the value for maxRequestSize attribute of the HttpRunTime).

A solution to this would, be, to change that value and update it to make it of your own choice.

Following shows an example of that, you can definitely add more attributes to create (or maintain or update) your configuration of the website in IIS.

<configuration>
   <system.web>
      <httpruntime maxrequestlength="100000" />
   </system.web>
</configuration>





注意: Th上述方法中的文件大小为100mb(当然因为MB为1024kb而不是1000kb),定义的大小以千字节为单位。有关这方面的更多信息,请阅读本文档。 https://msdn.microsoft.com/en-us/library/ e1f13641%28v = vs.71%29.aspx



Note: The file size in above method is 100mb (less than that of course because an MB is of 1024kb not 1000kb), size defined is in kilobytes. For more on this, please read this documentation. https://msdn.microsoft.com/en-us/library/e1f13641%28v=vs.71%29.aspx


我解决了这个问题..







[WebMethod]

public void UploadFileServer()// string filename

{

string filename = @D:\Old Songs\RDBurman\019__HUMEIN_TUMSE_PYAAR_KIT.MP3; // @D:\ Old Songs\R.D.Burman\015__SAGAR_KINARE.MP3; // + System.IO.Path.GetFileName(fileUpload1.PostedFile.FileName); // + System.IO.Path.GetFileName(fileUpload1.PostedFile.FileName); //@\"E:\MV\Rio.mkv\";//@\"E:\Downloads\movie\Noah.2013.BRRiP.XVID.AC3-MAJESTIC\Noah.2013.BRRiP.XVID的AC3-MAJESTIC.avi; //@\"E:\MV\Rio.mkv\";//

试试

{

//获取确切文件路径中的名称

String strFile = System.IO.Path.GetFileName(filename);



//创建网络实例服务



//TestUploader.Uploader.FileUploader srv = new

//TestUploader.Uploader.FileUploader();



MyWebService srv = new MyWebService();



//从选定文件中获取文件信息

FileInfo fInfo = new FileInfo(filename);



//获取文件的长度以查看是否可以

//上传它(标准的4 MB限制)

long numBytes = fInfo.Length;

double dLen = Convert.ToDouble(fInfo.Length / 10000000000);



// Def Web服务器上4 MB的ault限制

//必须将web.config更改为

//你想允许更大的上传

if(dLen< 5000000)

{

//为

//选择的文件设置文件流和二进制阅读器

FileStream fStream = new FileStream(filename,FileMode.Open,FileAccess.Read);

BinaryReader br = new BinaryReader(fStream);



//将文件转换为字节数组

byte [] data = br.ReadBytes((int)numBytes);

br.Close();



//将字节数组(文件)和文件名传递给Web服务

//字符串sTmp = srv.UploadFile(data,strFile) ;

string sTmp = TransferFile(data,strFile);

fStream.Close();

fStream.Dispose();



//除非发生错误,否则总会说OK,

//如果发生错误,服务vice返回错误消息



Console.WriteLine(文件上传状态:+ sTmp,文件上传);



}

其他

{

//如果文件太大而无法上传,则显示消息

Console.WriteLine(所选文件超过上传的大小限制。,文件大小);

}

}

catch(exception ex)

{

//向用户显示错误消息

//MessageBox.Show(ex.Message .ToString(),上传错误);

Console.WriteLine(ex.ToString());

}

}











//方法商店在服务器文件夹中

private FtpWebRequest ftpRequest = null;

// private FtpWebResponse ftpResp onse = null;

private Stream ftpStream = null;

private int bufferSize = 5048;





公共字符串TransferFile(byte [] fileContent,string filename)//文件文件// byte []文件,字符串文件名

{

// int l = Convert.ToInt32(file.Leanth);



// byte [] binaryWriteArray = new byte [file [0] .InputStream.Length];



// HttpContext postedContext = HttpContext.Current;



// byte [] data = br.ReadBytes( (int)numBytes);





string strMsg = string.Empty;

试试

{



/ *创建FTP请求* /

字符串uploadUrl = String.Format({0} / { 1} / {2},ftp://abc.co.in//VoiceChatServiceApp,/ UplodadedAudio /,filename);

// HttpWebRequest ftpRequest =(HttpWebRequest)WebRequest。 CRE ate(uploadUrl);

ftpRequest =(FtpWebRequest)FtpWebRequest.Create(uploadUrl);

/ *使用用户名和密码登录FTP服务器* /

ftpRequest.Credentials = new NetworkCredential(UserName,Password);

/ *如有疑问,请使用这些选项* /

//ftpRequest.UseBinary = true;

//ftpRequest.UsePassive = true;

//ftpRequest.KeepAlive = true;

/ *指定FTP请求的类型* /

ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

尝试

{



ftpRequest.ContentLength = fileContent.Length;



流requestStream = ftpRequest.GetRequestStream();

requestStream.Write(fileContent,0,fileContent.Length);

reque stStream.Close();

// FtpWebResponse response =(FtpWebResponse)ftpRequest.GetResponse();

// HttpWebResponse response =(HttpWebResponse)ftpRequest.GetResponse();

// strMsg =文件上传状态:+ response.ToString();



}

catch(Exception ex)

{

Console.WriteLine(ex.ToString());

}

/ *资源清理* /

ftpStream.Close();

ftpRequest = null;

}

catch (例外情况)

{

Console.WriteLine(ex.ToString());

}



返回strMsg;



}
I have solution this problem ..



[WebMethod]
public void UploadFileServer()//string filename
{
string filename = @"D:\Old Songs\R.D.Burman\019__HUMEIN_TUMSE_PYAAR_KIT.MP3"; // @"D:\Old Songs\R.D.Burman\015__SAGAR_KINARE.MP3"; //+ System.IO.Path.GetFileName(fileUpload1.PostedFile.FileName); // + System.IO.Path.GetFileName(fileUpload1.PostedFile.FileName); //@"E:\MV\Rio.mkv";//@"E:\Downloads\movie\Noah.2013.BRRiP.XVID.AC3-MAJESTIC\Noah.2013.BRRiP.XVID.AC3-MAJESTIC.avi"; //@"E:\MV\Rio.mkv";//
try
{
// get the exact file name from the path
String strFile = System.IO.Path.GetFileName(filename);

// create an instance fo the web service

//TestUploader.Uploader.FileUploader srv = new
//TestUploader.Uploader.FileUploader();

MyWebService srv = new MyWebService();

// get the file information form the selected file
FileInfo fInfo = new FileInfo(filename);

// get the length of the file to see if it is possible
// to upload it (with the standard 4 MB limit)
long numBytes = fInfo.Length;
double dLen = Convert.ToDouble(fInfo.Length / 10000000000);

// Default limit of 4 MB on web server
// have to change the web.config to if
// you want to allow larger uploads
if (dLen < 5000000)
{
// set up a file stream and binary reader for the
// selected file
FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);

// convert the file to a byte array
byte[] data = br.ReadBytes((int)numBytes);
br.Close();

// pass the byte array (file) and file name to the web service
// string sTmp = srv.UploadFile(data, strFile);
string sTmp = TransferFile(data,strFile);
fStream.Close();
fStream.Dispose();

// this will always say OK unless an error occurs,
// if an error occurs, the service returns the error message

Console.WriteLine("File Upload Status: " + sTmp, "File Upload");

}
else
{
// Display message if the file was too large to upload
Console.WriteLine("The file selected exceeds the size limit for uploads.", "File Size");
}
}
catch (Exception ex)
{
// display an error message to the user
//MessageBox.Show(ex.Message.ToString(), "Upload Error");
Console.WriteLine(ex.ToString());
}
}





// Method Store in server folder
private FtpWebRequest ftpRequest = null;
//private FtpWebResponse ftpResponse = null;
private Stream ftpStream = null;
private int bufferSize = 5048;


public string TransferFile(byte[] fileContent,string filename) //File file //byte[] file, string filename
{
//int l = Convert.ToInt32(file.Leanth);

// byte[] binaryWriteArray = new byte[file[0].InputStream.Length];

//HttpContext postedContext = HttpContext.Current;

//byte[] data = br.ReadBytes((int)numBytes);


string strMsg = string.Empty;
try
{

/* Create an FTP Request */
String uploadUrl = String.Format("{0}/{1}/{2}", "ftp://abc.co.in//VoiceChatServiceApp", "/UplodadedAudio/", filename);
// HttpWebRequest ftpRequest = (HttpWebRequest)WebRequest.Create(uploadUrl);
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(uploadUrl);
/* Log in to the FTP Server with the User Name and Password Provided */
ftpRequest.Credentials = new NetworkCredential("UserName", "Password");
/* When in doubt, use these options */
//ftpRequest.UseBinary = true;
//ftpRequest.UsePassive = true;
//ftpRequest.KeepAlive = true;
/* Specify the Type of FTP Request */
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
try
{

ftpRequest.ContentLength = fileContent.Length;

Stream requestStream = ftpRequest.GetRequestStream();
requestStream.Write(fileContent, 0, fileContent.Length);
requestStream.Close();
//FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
//HttpWebResponse response = (HttpWebResponse)ftpRequest.GetResponse();
//strMsg = "File Upload Status: " + response.ToString();

}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
/* Resource Cleanup */
ftpStream.Close();
ftpRequest = null;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

return strMsg;

}


这篇关于如何上传大文件2 GB或更多大小文件上传服务器文件夹在asp.net c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆