使用文件上传控件上传大文件 [英] Uploading large file using file upload control

查看:115
本文介绍了使用文件上传控件上传大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我们的网站上,我们正在使用文件上传控件来上传和下载文件.在将其上传到服务器之前,我们先使用XML序列化器对内容进行序列化,然后使用Rijndael算法对数据进行加密,然后将文件保存在服务器中.使用 maxRequestLength ="71680" executionTimeout ="300" 的web.config httpRuntime

问题是我可以上传多个大小为10 mb的文件.但是当我尝试上传大小为40 mb的文件时,它抛出了内存不足"异常.

Memorystream没有阻止文件内容.
有什么办法可以上传吗?

Hi,

In our website,we are using fileupload control to upload and download files.Before uploading it to the server,we are serialsing the content using XML serialiser and then encrypting the data using Rijndael algorithm and then save the file in server.I have set up the web.config httpRuntime with maxRequestLength="71680" executionTimeout="300"

The problem is that I can able to upload multiple files of size 10 mb.but when i try to upload file of size 40mb,it is throwing " out of memory " exception.

Memorystream is not holding up the filecontent.
Is there any way to do upload??

//Serialise
      public string SerializeAnObject(object anObject, int fileLen)
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlSerializer xml_Serializer = new XmlSerializer(anObject.GetType());
            MemoryStream memStream = new MemoryStream(fileLen);
            try
            {
                xml_Serializer.Serialize(memStream, anObject);
                memStream.Position = 0;
                xmlDoc.Load(memStream);
                return xmlDoc.InnerXml.ToString();
            }
            finally
            {
                memStream.Close();
            }
        }

// encryption
 public string Encrypt(string textToBeEncrypted, string strConn, int fileLen)
        {
            RijndaelManaged rijndaelCipher = new RijndaelManaged();
            string password = strConn;
            byte[] plainText = new byte[fileLen + 1];
            plainText = System.Text.Encoding.Unicode.GetBytes(textToBeEncrypted);
            byte[] salt = Encoding.ASCII.GetBytes(password.Length.ToString());
            PasswordDeriveBytes secretKey = new PasswordDeriveBytes(password, salt);        
// Creates a symmetric encryptor object.
            ICryptoTransform encryptor = rijndaelCipher.CreateEncryptor(secretKey.GetBytes(32), secretKey.GetBytes(16));
           using (MemoryStream memoryStream = new MemoryStream(fileLen))
            {
                using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                {
                    cryptoStream.Write(plainText, 0, plainText.Length);
 // Writes the final state and clears the buffer        
                    cryptoStream.FlushFinalBlock();
                    byte[] cipherBytes = memoryStream.ToArray();
                    memoryStream.Close();
                    cryptoStream.Close();
                    string encryptedData = Convert.ToBase64String(cipherBytes);
                    return encryptedData;
                }
            }
        }

推荐答案

哈哈! asp.net FileUpload.当您处理要上传的小文件时,asp.net文件上传控件的工作就不错.一旦开始增加文件大小,破坏程度也会随之增加.

我过去处理过这个问题,并且非常了解您的无奈.对于初学者,阅读此内容. [ ^ ].然后,我会考虑将文件上传控件替换为另一个不错的控件.有大量的FileUpload控件,包括免费的和商业的.

就我而言,我最终通过 Darren Johnstone [
Aha! asp.net FileUpload. The asp.net file upload control does a decent job when you dealing small files to upload. As soon as you start increasing the file size, frastration level increases as well.

I dealt with this in the past and know very well your frustration. For starters read this one.[^]. Then I would consider replacing the file upload control another decent control. There are tons of FileUpload controls, both free and commericial.

In my case I ended up using asp.net file upload control by Darren Johnstone[^] and it works like a charm.


这篇关于使用文件上传控件上传大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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