Upload Large Audio File
-
Hi, I am uploading large audio file using webclient in windows form. Now if file is small then it is uploading but if file is larger in size like 200 mb or more then it showing exception that System.OutOfMemoryException . So How can I solved it. My code is give below. WebClient client = new WebClient(); Stream stream = client.OpenWrite(remoteFilename, "PUT"); // The buffer size is set to 2kb const int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; // Opens a file stream (System.IO.FileStream) to read the file // to be uploaded FileStream fs = fileInf.OpenRead(); int doneSoFar = 0; // Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength); //added for accurate progress doneSoFar += contentLen; setItemStatus("Uploading"); while (contentLen != 0) { setItemProgress(doneSoFar, fileInf.Length); // Write Content from the file stream to the FTP Upload Stream stream.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); doneSoFar += contentLen; } // Close the file stream and the Request Stream stream.Close(); fs.Close(); Thanks sjs
-
Hi, I am uploading large audio file using webclient in windows form. Now if file is small then it is uploading but if file is larger in size like 200 mb or more then it showing exception that System.OutOfMemoryException . So How can I solved it. My code is give below. WebClient client = new WebClient(); Stream stream = client.OpenWrite(remoteFilename, "PUT"); // The buffer size is set to 2kb const int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; // Opens a file stream (System.IO.FileStream) to read the file // to be uploaded FileStream fs = fileInf.OpenRead(); int doneSoFar = 0; // Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength); //added for accurate progress doneSoFar += contentLen; setItemStatus("Uploading"); while (contentLen != 0) { setItemProgress(doneSoFar, fileInf.Length); // Write Content from the file stream to the FTP Upload Stream stream.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); doneSoFar += contentLen; } // Close the file stream and the Request Stream stream.Close(); fs.Close(); Thanks sjs
-
Are you running this in a Thread?
Excellence is doing ordinary things extraordinarily well.
-
Hi Thanks for reply.. I am not using any thread. Can you pls show me how can i write thread in the above mention code Thanks Sjs
modified on Saturday, March 6, 2010 5:03 AM
It is pretty simple though. Make sure you add
using System.Threading;
private void btn_StartLoad_Click(object sender, EventArgs e) { ThreadStart startload = new ThreadStart(startUpload); Thread threadload = new Thread(startload); threadload.Start(); } private void startUpload() { //Put your code here }
Excellence is doing ordinary things extraordinarily well.
-
It is pretty simple though. Make sure you add
using System.Threading;
private void btn_StartLoad_Click(object sender, EventArgs e) { ThreadStart startload = new ThreadStart(startUpload); Thread threadload = new Thread(startload); threadload.Start(); } private void startUpload() { //Put your code here }
Excellence is doing ordinary things extraordinarily well.