开发者

How to create Large resumable download from a secured location .NET

I need to preface I'm not a .NET coder at all, but to get partial functionality, I modified a technet chunkedfilefetch.aspx script that uses chunked Data Reading and writing Streamed method of doing file transfer, to get me half-way.

iStream = New System.IO.FileStream(path, System.IO.FileMode.Open, _
    IO.FileAccess.Read, IO.FileShare.Read)
dataToRead = iStream.Length

Response.Co开发者_开发问答ntentType = "application/octet-stream"
Response.AddHeader("Content-Length", file.Length.ToString())
Response.AddHeader("Content-Disposition", "attachment; filename=" & filedownload)

' Read and send the file 16,000 bytes at a time. '
While dataToRead > 0
    If Response.IsClientConnected Then
        length = iStream.Read(buffer, 0, 16000)
        Response.OutputStream.Write(buffer, 0, length)
        Response.Flush()
        ReDim buffer(16000) ' Clear the buffer '
        dataToRead = dataToRead - length
    Else
        ' Prevent infinite loop if user disconnects '
        dataToRead = -1
    End If
End While

This works great on files up to 2GB and is fully functioning now.. But only one problem it doesn't allow for resume.

I took the original code called it fetch.aspx and pass an orderNUM through the URL. fetch.aspx&ordernum=xxxxxxx It then reads the filename/location from the database occording to the ordernumber, and chunks it out from a secured location NOT under the webroot.

I need a way to make this resumable, by the nature of the internet and large files people always get disconnected and would like to resume where they left off. But any resumable articles i've read, assume the file is within the webroot.. ie. http://www.devx.com/dotnet/Article/22533/1954 Great article and works well, but I need to stream from a secured location.

I'm not a .NET coder at all, at best i can do a bit of coldfusion, if anyone could help me modify a handler to do this, i would really appreciate it.

Requirements:

  • I Have a working fetch.aspx script that functions well and uses the above code snippet as a base for the streamed downloading.
  • Download files are large 600MB and are stored in a secured location outside of the webroot.
  • Users click on the fetch.aspx to start the download, and would therefore be clicking it again if it was to fail. If the ext is a .ASPX and the file being sent is a AVI, clicking on it would completely bypass an IHTTP handler mapped to .AVI ext, so this confuses me
  • From what I understand the browser will read and match etag value and file modified date to determine they are talking about the same file, then a subsequent accept-range is exchanged between the browser and IIS. Since this dialog happens with IIS, we need to use a handler to intercept and respond accordingly, but clicking on the link would send it to an ASPX file which the handeler needs to be on an AVI fiel.. Also confusing me.
  • If there is a way to request the initial HTTP request header containing etag, accept-range into the normal .ASPX file, i could read those values and if the accept-range and etag exist, start chunking at that byte value somehow? but I couldn't find a way to transfer the http request headers since they seem to get lost at the IIS level.

  • OrderNum which is passed in the URL string is unique and could be used as the ETag

        Response.AddHeader("ETag", request("ordernum"))
    
  • Files need to be resumable and chunked out due to size.

  • File extensions are .AVI so a handler could be written around it.
  • IIS 6.0 Web Server

Any help would really be appreciated, i've been reading and reading and downloading code, but none of the examples given meet my situation with the original file being streamed from outside of the webroot. Please help me get a handle on these httphandlers :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜