如何在数据库中上传大文件
本文关键字:文件 数据库 | 更新日期: 2023-09-27 18:34:33
protected void Button1_Click(object sender, EventArgs e)
{
//Uploading file from Computer to Database(server)
String filename = "", filetype = "", filesize = "";
if (FileUpload1.HasFile)
{
UploadLogic bl=new UploadLogic();
filename = FileUpload1.PostedFile.FileName;
filesize = FileUpload1.PostedFile.ContentLength.ToString();
filetype = FileUpload1.PostedFile.ContentType;
byte[] filepath = new byte[FileUpload1.PostedFile.ContentLength];
FileUpload1.PostedFile.InputStream.Read(filepath, 0, FileUpload1.PostedFile.ContentLength);
int i = bl.upload_file(filename, filesize, filetype, filepath);
DataSet ds = new DataSet();
ds = bl.uploaded_Content();
ListBox1.DataSource = ds;
ListBox1.DataTextField = "File_Name";
ListBox1.DataValueField = "File_Name";
//Bind your Data
ListBox1.DataBind();
}
}
此代码仅上传小于 1MB 的文件。如果我想上传大文件,它不会发生。谁能告诉我为什么?
看看 httpRuntime
您需要编辑web.config
<configuration>
<system.web>
<httpRuntime maxRequestLength="SIZE" />
</system.web>
</configuration>
默认情况下,它将设置为4096kb
无论如何,如果文件大小相当高,将文件上传到数据库将是一个很好的解决方案。
编辑你的 web.config
<httpRuntime useFullyQualifiedRedirectUrl="true|false"
maxRequestLength="size in kbytes"
executionTimeout="seconds"
minFreeThreads="number of threads"
minFreeLocalRequestFreeThreads="number of threads"
appRequestQueueLimit="number of requests"
versionHeader="version string"/>
源元素