Ускорение загрузки файлов
Я создаю загрузчик файлов в ASP.NET используя C#, но когда я загружаю большой файл, он занимает много времени для загрузки
Как мне его ускорить?
Что я уже пробовал:
protected void Button1_Click(object sender, EventArgs e) { if (FileUpload1.HasFiles) { foreach (HttpPostedFile postedfile in FileUpload1.PostedFiles) { byte[] img = new byte[postedfile.ContentLength]; postedfile.InputStream.Read(img, 0, postedfile.ContentLength); string file_ext = postedfile.FileName; string ext = Path.GetExtension(file_ext); // ftp if ((ext.ToLower() == ".jpg") || (ext.ToLower() == ".jpeg") || (ext.ToLower() == ".gif") || (ext.ToLower() == ".png")) { Random rnd = new Random(); int card = rnd.Next(); string location_filename = "/Album/" + Album_Id + "/" + card + "_" + file_ext; System.Windows.Forms.MessageBox.Show(location_filename); MemoryStream stream = new MemoryStream(img); System.Drawing.Image image = System.Drawing.Image.FromStream(stream); if ((image.Width > 250 && image.Width < 3650) && (image.Height > 250) && image.Height < 4450) { ftp_class.UploadFileToFTP(img, location_filename); } else { // Label1.Text = "Image is To Large"; } // File.WriteAllBytes(Server.MapPath("~/Property/") + Property_ID + "/" + card + file_ext, img); } } }
public class ftp_class { static String ftpusername = "Ftp_ExampleCodeExample"; // e.g. username static String ftppassword = "Example@123"; // e.g. password public static void CreateDirectoryToFTP(string directory) { try { // Directory.CreateDirectory(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "/" + directory); FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create("ftp://example.com/" + directory); ftp.Credentials = new NetworkCredential(ftpusername, ftppassword); ftp.KeepAlive = true; ftp.UseBinary = true; ftp.Method = WebRequestMethods.Ftp.MakeDirectory; FtpWebResponse responseFileDelete = (FtpWebResponse)ftp.GetResponse(); } catch (Exception ex) { // alert_message.alert_message_show("ftp:" + ex); } } public static void UploadFileToFTP(byte[] img, string location_filename) { try { // File.WriteAllBytes(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "/" + location_filename, img); FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create("ftp://example.com/" + location_filename); ftp.Credentials = new NetworkCredential(ftpusername, ftppassword); ftp.KeepAlive = true; ftp.UseBinary = true; ftp.Method = WebRequestMethods.Ftp.UploadFile; Stream ftpstream = ftp.GetRequestStream(); ftpstream.Write(img, 0, img.Length); ftpstream.Close(); } catch (Exception ex) { //extra.alter_box("" + ex); // alert_message.alert_message_show("ftp:" + ex); } } }