File downloader 'resume' problem
-
I have a VS2005 web project that provides file content download. Since some files are large I want to be able to pause/resume the download. I have added the 'Range' header and byte marker but am getting two problems: 1) File name is getting corrupted with a ',' comma character on the end of the file name (i.e. 'File.zip' shows in the save dialog as 'file.zip,' - could this be a cached file name suggestion? 2) The resume won't fire (possibly due to problem 1) Environment is IIS6, VS2k5/C#/ASPX. Have tried with FireFox (3.5.2) and Internet Download manager. Here's the code - TIA
if (File.Exists(strFilePath)) { byte[] buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; int length; long dataToRead, dataLength, bytesDownloaded; long start = 0; string range = Request.Headers["Range"]; if (range != null) { range = range.Replace("bytes=", ""); range = range.Substring(0, range.IndexOf("-")); start = Int64.Parse(range); } Response.Expires = 0; bytesDownloaded = 0; using (FileStream dlStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (start > 0) { dlStream.Seek(start, SeekOrigin.Begin); dataToRead = dlStream.Length - start; } else { dataToRead = dlStream.Length; } dataLength = dataToRead; Response.AddHeader("Content-Disposition", "attachment; filename=\"" + dlStream.Name.Substring(dlStream.Name.LastIndexOf(@"\") + 1) + "\""); Response.AddHeader("Content-Length", dlStream.Length.ToString()); length = dlStream.Read(buffer, 0, Int32.Parse(Config.Settings["bufferSize"])); while (dataToRead > 0) { if (Response.IsClientConnected) { Response.OutputStream.Write(buffer, 0, length); bytesDownloaded += length; Response.Flush(); buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; data
-
I have a VS2005 web project that provides file content download. Since some files are large I want to be able to pause/resume the download. I have added the 'Range' header and byte marker but am getting two problems: 1) File name is getting corrupted with a ',' comma character on the end of the file name (i.e. 'File.zip' shows in the save dialog as 'file.zip,' - could this be a cached file name suggestion? 2) The resume won't fire (possibly due to problem 1) Environment is IIS6, VS2k5/C#/ASPX. Have tried with FireFox (3.5.2) and Internet Download manager. Here's the code - TIA
if (File.Exists(strFilePath)) { byte[] buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; int length; long dataToRead, dataLength, bytesDownloaded; long start = 0; string range = Request.Headers["Range"]; if (range != null) { range = range.Replace("bytes=", ""); range = range.Substring(0, range.IndexOf("-")); start = Int64.Parse(range); } Response.Expires = 0; bytesDownloaded = 0; using (FileStream dlStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (start > 0) { dlStream.Seek(start, SeekOrigin.Begin); dataToRead = dlStream.Length - start; } else { dataToRead = dlStream.Length; } dataLength = dataToRead; Response.AddHeader("Content-Disposition", "attachment; filename=\"" + dlStream.Name.Substring(dlStream.Name.LastIndexOf(@"\") + 1) + "\""); Response.AddHeader("Content-Length", dlStream.Length.ToString()); length = dlStream.Read(buffer, 0, Int32.Parse(Config.Settings["bufferSize"])); while (dataToRead > 0) { if (Response.IsClientConnected) { Response.OutputStream.Write(buffer, 0, length); bytesDownloaded += length; Response.Flush(); buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; data
TCHamilton wrote:
Since some files are large I want to be able to pause/resume the download.
In that case, why not check out the Background Intelligent Transfer Service[^]?
"I do not care if it works on your system, I am not gonna ship your computer."
-
I have a VS2005 web project that provides file content download. Since some files are large I want to be able to pause/resume the download. I have added the 'Range' header and byte marker but am getting two problems: 1) File name is getting corrupted with a ',' comma character on the end of the file name (i.e. 'File.zip' shows in the save dialog as 'file.zip,' - could this be a cached file name suggestion? 2) The resume won't fire (possibly due to problem 1) Environment is IIS6, VS2k5/C#/ASPX. Have tried with FireFox (3.5.2) and Internet Download manager. Here's the code - TIA
if (File.Exists(strFilePath)) { byte[] buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; int length; long dataToRead, dataLength, bytesDownloaded; long start = 0; string range = Request.Headers["Range"]; if (range != null) { range = range.Replace("bytes=", ""); range = range.Substring(0, range.IndexOf("-")); start = Int64.Parse(range); } Response.Expires = 0; bytesDownloaded = 0; using (FileStream dlStream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (start > 0) { dlStream.Seek(start, SeekOrigin.Begin); dataToRead = dlStream.Length - start; } else { dataToRead = dlStream.Length; } dataLength = dataToRead; Response.AddHeader("Content-Disposition", "attachment; filename=\"" + dlStream.Name.Substring(dlStream.Name.LastIndexOf(@"\") + 1) + "\""); Response.AddHeader("Content-Length", dlStream.Length.ToString()); length = dlStream.Read(buffer, 0, Int32.Parse(Config.Settings["bufferSize"])); while (dataToRead > 0) { if (Response.IsClientConnected) { Response.OutputStream.Write(buffer, 0, length); bytesDownloaded += length; Response.Flush(); buffer = new byte[Int32.Parse(Config.Settings["bufferSize"])]; data
-
TCHamilton wrote:
Since some files are large I want to be able to pause/resume the download.
In that case, why not check out the Background Intelligent Transfer Service[^]?
"I do not care if it works on your system, I am not gonna ship your computer."
Hi Eddy, I'm not familiar yet with BITS - will explore now. The issue really is how/what's missing in my attempt to facilitate 'resume a paused download...' Web site is public facing that supports various browsers - I've been asked to make sure it can handle IE6 and Safari primarily, not sure if BITS is relevent in that context. I'm sure the target browser limitation will relax, but first I need to get 'resume' to work.
Tom
-
Still having problem - unable to set the Response Headers :
Response.AddHeader("Content-Disposition", "attachment; filename=" + Convert.ToString(Server.UrlDecode(Request["FileName"])));
Response.AddHeader("Content-Length", dlStream.Length.ToString());
The system gives message that: Headers: 'Response.Headers' threw an exception of type 'System.PlatformNotSupportedException' The system is Win2k3 IIS6. VS2k5 Confused... Thank you for any help or suggestions
Tom
-
Still having problem - unable to set the Response Headers :
Response.AddHeader("Content-Disposition", "attachment; filename=" + Convert.ToString(Server.UrlDecode(Request["FileName"])));
Response.AddHeader("Content-Length", dlStream.Length.ToString());
The system gives message that: Headers: 'Response.Headers' threw an exception of type 'System.PlatformNotSupportedException' The system is Win2k3 IIS6. VS2k5 Confused... Thank you for any help or suggestions
Tom
Well, mystery solved - response headers were being set, just not obvious with IIS 6, have to track them down via DEBUG/Watch with code that can enum the Custom Header array
((System.Web.HttpResponseHeader)((new System.Collections.ArrayList.ArrayListDebugView(Response._customHeaders)).Items[0])).Name "Accept-Ranges" ((System.Web.HttpResponseHeader)((new System.Collections.ArrayList.ArrayListDebugView(Response._customHeaders)).Items[0])).Value "bytes"
Able to verify Header set, and respond to resume download 'Range' Thanks allTom