file size limit in Response.binarywrite

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • S N

    file size limit in Response.binarywrite

    I am using the following code to hide the download url of files on my website. The code uses Response.Binary write to send file to the client.
    Kindly indicate the maximum size of the file that can be downloaded using this method.
    I am hosting this site on a public server, so I will not be able to change anything on the webserver. Kindly indicate what can be done to ensure that the above method remains valid for any file size download.

    call Response.AddHea der("Content-Disposition","a ttachment; filename=""" & strFileSave & """")
    Response.Conten tType = "bad/type"
    Set Fsys = Server.CreateOb ject("Scripting .FileSystemObje ct")
    Set TS = Fsys.GetFile(st rFile).OpenAsTe xtStream(1, -1)
    Do While Not (TS.AtEndOfStre am)
    Response.Binary Write(TS.Read(1 ))
    Loop
  • =?Utf-8?B?T2xkIFBlZGFudA==?=

    #2
    RE: file size limit in Response.binary write

    "S N" wrote:
    I am using the following code to hide the download url of files on my website. The code uses Response.Binary write to send file to the client.
    Kindly indicate the maximum size of the file that can be downloaded using this method.
    call Response.AddHea der("Content-Disposition","a ttachment; filename=""" & strFileSave & """")
    Response.Conten tType = "bad/type"
    Set Fsys = Server.CreateOb ject("Scripting .FileSystemObje ct")
    Set TS = Fsys.GetFile(st rFile).OpenAsTe xtStream(1, -1)
    Do While Not (TS.AtEndOfStre am)
    Response.Binary Write(TS.Read(1 ))
    Loop
    Ummm...that code isn't goint to work, anyway. See the method
    OpenAsTEXTstrea m
    ???

    You really can only use FileSystemObjec t reliably with text files; it wasn't
    designed to work with binary files.

    You need to use ADODB.Stream object, instead.


    And then you could easily control the amount you write in each chunk by just
    limiting the amount you Read each time.

    Comment

    • S N

      #3
      Re: file size limit in Response.binary write

      Thanks for the advice. I was under the impression that ADODB can be used
      only for databases. This is the first instance of using it on files.
      Can you please provide a sample code to hide download url by using ADODB
      stream, while there should be no limit on the size of files to be
      downloaded.

      ..
      "Old Pedant" <OldPedant@disc ussions.microso ft.comwrote in message
      news:C37071C4-3FB6-446F-BF6A-3755BFEC28BE@mi crosoft.com...
      "S N" wrote:
      >
      >I am using the following code to hide the download url of files on my
      >website. The code uses Response.Binary write to send file to the client.
      >Kindly indicate the maximum size of the file that can be downloaded using
      >this method.
      >call Response.AddHea der("Content-Disposition","a ttachment; filename=""" &
      >strFileSave & """")
      > Response.Conten tType = "bad/type"
      > Set Fsys = Server.CreateOb ject("Scripting .FileSystemObje ct")
      > Set TS = Fsys.GetFile(st rFile).OpenAsTe xtStream(1, -1)
      > Do While Not (TS.AtEndOfStre am)
      > Response.Binary Write(TS.Read(1 ))
      > Loop
      >
      Ummm...that code isn't goint to work, anyway. See the method
      OpenAsTEXTstrea m
      ???
      >
      You really can only use FileSystemObjec t reliably with text files; it
      wasn't
      designed to work with binary files.
      >
      You need to use ADODB.Stream object, instead.

      >
      And then you could easily control the amount you write in each chunk by
      just
      limiting the amount you Read each time.
      >

      Comment

      • =?Utf-8?B?T2xkIFBlZGFudA==?=

        #4
        Re: file size limit in Response.binary write



        "S N" wrote:
        Can you please provide a sample code to hide download url by using ADODB
        stream, while there should be no limit on the size of files to be
        downloaded.
        Good old Atrax has a couple of demos.

        Note that his code is written in JScript for ASP, but conversion to VBScript
        should be easy.


        and


        If you need more help, ask.

        Comment

        • S N

          #5
          Re: file size limit in Response.binary write

          I would be grateful if you can give me vbscript code as well.
          I would also like to clarify that the code for jscript forces save as
          dialog. What if we want to hide the download url but dont want to force the
          save as dialog, instead just want to see the pdf file within the browser
          window itself.
          Kindly advise on this.

          Thanks in anticipation.

          "Old Pedant" <OldPedant@disc ussions.microso ft.comwrote in message
          news:03E3B997-93DE-4D4B-8C49-F5102BB39CEA@mi crosoft.com...
          >
          >
          "S N" wrote:
          >
          >Can you please provide a sample code to hide download url by using ADODB
          >stream, while there should be no limit on the size of files to be
          >downloaded.
          >
          Good old Atrax has a couple of demos.
          >
          Note that his code is written in JScript for ASP, but conversion to
          VBScript
          should be easy.
          >

          and

          >
          If you need more help, ask.
          >

          Comment

          • Anthony Jones

            #6
            Re: file size limit in Response.binary write


            "S N" <uandme72@yahoo .comwrote in message
            news:unVr3cOEJH A.4492@TK2MSFTN GP05.phx.gbl...
            >I am using the following code to hide the download url of files on my
            >website. The code uses Response.Binary write to send file to the >client.
            >Kindly indicate the maximum size of the file that can be downloaded using
            >this method.
            >I am hosting this site on a public server, so I will not be able to change
            >anything on the webserver. Kindly indicate what can be done to >ensure that
            >the above method remains valid for any file size download.
            >
            >call Response.AddHea der("Content-Disposition","a ttachment; filename=""" &
            >strFileSave & """")
            Response.Conten tType = "bad/type"
            Set Fsys = Server.CreateOb ject("Scripting .FileSystemObje ct")
            Set TS = Fsys.GetFile(st rFile).OpenAsTe xtStream(1, -1)
            Do While Not (TS.AtEndOfStre am)
            Response.Binary Write(TS.Read(1 ))
            Loop
            Use this code:-

            Sub SendFileToRespo nse(FilePath, FileName)

            Const clChunkSize = 1048576 ' 1MB

            Dim oStream, i
            Response.Buffer = False

            Response.Conten tType = "applicatio n/octet-stream"
            Response.AddHea der "Content-Disposition", _
            "attachment ; Filename=" & FileName

            Set oStream = Server.CreateOb ject("ADODB.Str eam")
            oStream.Type = 1 ' Binary
            oStream.Open
            oStream.LoadFro mFile FilePath

            For i = 1 To oStream.Size \ clChunkSize
            Response.Binary Write oStream.Read(cl ChunkSize)
            Next
            If (oStream.Size Mod clChunkSize) <0 Then
            Response.Binary Write oStream.Read(oS tream.Size Mod clChunkSize)
            End If
            oStream.Close

            End Sub

            SendFileToRespo nse strFile, strFileSave

            Note the Response.Buffer = false allows you to send a file of any size.

            --
            Anthony Jones - MVP ASP/ASP.NET

            Comment

            • S N

              #7
              Re: file size limit in Response.binary write

              What if we want to use sendfiletorespo nse but dont want to force the save as
              dialog, instead just want to see the pdf file within the browser window
              itself.
              is there any change required in the code to achieve this.

              "Anthony Jones" <AnthonyWJones@ yadayadayada.co mwrote in message
              news:e5fWrklEJH A.4092@TK2MSFTN GP06.phx.gbl...
              >
              "S N" <uandme72@yahoo .comwrote in message
              news:unVr3cOEJH A.4492@TK2MSFTN GP05.phx.gbl...
              >>I am using the following code to hide the download url of files on my
              >>website. The code uses Response.Binary write to send file to the >client.
              >>Kindly indicate the maximum size of the file that can be downloaded using
              >>this method.
              >>I am hosting this site on a public server, so I will not be able to change
              >>anything on the webserver. Kindly indicate what can be done to >ensure
              >>that the above method remains valid for any file size download.
              >>
              >>call Response.AddHea der("Content-Disposition","a ttachment; filename=""" &
              >>strFileSave & """")
              > Response.Conten tType = "bad/type"
              > Set Fsys = Server.CreateOb ject("Scripting .FileSystemObje ct")
              > Set TS = Fsys.GetFile(st rFile).OpenAsTe xtStream(1, -1)
              > Do While Not (TS.AtEndOfStre am)
              > Response.Binary Write(TS.Read(1 ))
              > Loop
              >
              Use this code:-
              >
              Sub SendFileToRespo nse(FilePath, FileName)
              >
              Const clChunkSize = 1048576 ' 1MB
              >
              Dim oStream, i
              Response.Buffer = False
              >
              Response.Conten tType = "applicatio n/octet-stream"
              Response.AddHea der "Content-Disposition", _
              "attachment ; Filename=" & FileName
              >
              Set oStream = Server.CreateOb ject("ADODB.Str eam")
              oStream.Type = 1 ' Binary
              oStream.Open
              oStream.LoadFro mFile FilePath
              >
              For i = 1 To oStream.Size \ clChunkSize
              Response.Binary Write oStream.Read(cl ChunkSize)
              Next
              If (oStream.Size Mod clChunkSize) <0 Then
              Response.Binary Write oStream.Read(oS tream.Size Mod clChunkSize)
              End If
              oStream.Close
              >
              End Sub
              >
              SendFileToRespo nse strFile, strFileSave
              >
              Note the Response.Buffer = false allows you to send a file of any size.
              >
              --
              Anthony Jones - MVP ASP/ASP.NET
              >
              >

              Comment

              • Anthony Jones

                #8
                Re: file size limit in Response.binary write

                "S N" <uandme72@yahoo .comwrote in message
                news:%23$Hxh7oE JHA.5448@TK2MSF TNGP04.phx.gbl. ..
                What if we want to use sendfiletorespo nse but dont want to force the save
                as dialog, instead just want to see the pdf file within the browser window
                itself.
                is there any change required in the code to achieve this.
                >
                If you know its a pdf then change content-type to application/pdf and remove
                the attachment; keyword from content-disposition.

                --
                Anthony Jones - MVP ASP/ASP.NET

                Comment

                • S N

                  #9
                  Re: file size limit in Response.binary write

                  Following error received:

                  Response object error 'ASP 0157 : 80004005'
                  Buffering On

                  /test/dl.asp, line 2

                  Buffering cannot be turned off once it is already turned on.


                  Please note that I am hosting the site on a public server so there is no way
                  to ask the web admin to configure the server specifically for me. In such a
                  situation is it possible to eliminate the error as indicated above. Further,
                  if I am not able to switch off the response.buffer , will there be any
                  limitation on the size of file that i can download using
                  response.binary write?




                  "Anthony Jones" <AnthonyWJones@ yadayadayada.co mwrote in message
                  news:e94JHNpEJH A.5104@TK2MSFTN GP02.phx.gbl...
                  "S N" <uandme72@yahoo .comwrote in message
                  news:%23$Hxh7oE JHA.5448@TK2MSF TNGP04.phx.gbl. ..
                  >What if we want to use sendfiletorespo nse but dont want to force the save
                  >as dialog, instead just want to see the pdf file within the browser
                  >window itself.
                  >is there any change required in the code to achieve this.
                  >>
                  >
                  If you know its a pdf then change content-type to application/pdf and
                  remove the attachment; keyword from content-disposition.
                  >
                  --
                  Anthony Jones - MVP ASP/ASP.NET
                  >
                  >

                  Comment

                  • Anthony Jones

                    #10
                    Re: file size limit in Response.binary write

                    "S N" <uandme72@yahoo .comwrote in message
                    news:u4hyiirEJH A.4420@TK2MSFTN GP06.phx.gbl...
                    Following error received:
                    >
                    Response object error 'ASP 0157 : 80004005'
                    Buffering On
                    >
                    /test/dl.asp, line 2
                    >
                    Buffering cannot be turned off once it is already turned on.
                    >
                    You get this error if there is anything in your page or includes at the top
                    of the page which writes stuff to the response before your code has run.
                    Note any static content in the page will be sent.

                    Typical a page of this sort looks like:-

                    <!-- #include .... some common include -->
                    <%

                    ' Code here that should note writing anything.
                    'My code I posted to you with your mods.
                    %>

                    Where the include is of a similar structure defininng constants and utility
                    functions.
                    >
                    Please note that I am hosting the site on a public server so there is no
                    way to ask the web admin to configure the server specifically for me.
                    Whilst an admin may have configured the buffer to be on (which is the
                    default) you can set it off as long as you do so before sending anything.
                    >In such a situation is it possible to eliminate the error as indicated
                    >above. Further, if I am not able to switch off the response.buffer , will
                    >there be any limitation on the size of file that i can download using
                    >response.binar ywrite?
                    >
                    Without turning it off there will be a limitation. The is a buffer size
                    limit that a public server administrator will almost certainly have
                    configured (the default on IIS6 is 4MB).

                    --
                    Anthony Jones - MVP ASP/ASP.NET

                    Comment

                    • S N

                      #11
                      Re: file size limit in Response.binary write

                      Also advise the content type in case the file is an excel file, word
                      document, exe file, zip file etc.

                      Thanks in advance.


                      "Anthony Jones" <AnthonyWJones@ yadayadayada.co mwrote in message
                      news:e94JHNpEJH A.5104@TK2MSFTN GP02.phx.gbl...
                      "S N" <uandme72@yahoo .comwrote in message
                      news:%23$Hxh7oE JHA.5448@TK2MSF TNGP04.phx.gbl. ..
                      >What if we want to use sendfiletorespo nse but dont want to force the save
                      >as dialog, instead just want to see the pdf file within the browser
                      >window itself.
                      >is there any change required in the code to achieve this.
                      >>
                      >
                      If you know its a pdf then change content-type to application/pdf and
                      remove the attachment; keyword from content-disposition.
                      >
                      --
                      Anthony Jones - MVP ASP/ASP.NET
                      >
                      >

                      Comment

                      • =?Utf-8?B?T2xkIFBlZGFudA==?=

                        #12
                        Re: file size limit in Response.binary write



                        "S N" wrote:
                        Just one clarification
                        You intended
                        For i = 1 To oStream.Size / clChunkSize
                        or
                        For i = 1 To oStream.Size \ clChunkSize
                        He *intended* the latter.

                        The backslash operator means "integer division" in VBScript (and VB and
                        VB.NET) code.

                        That is,
                        a \ b
                        is equivalent to
                        INT( a / b )

                        *************** *****

                        Also, you don't need to mess with Response.Buffer =False, at all.

                        Just follow each
                        Response.Binary Write
                        with
                        Response.Flush

                        Now the buffer will never get more full than one "chunkSize" .


                        Comment

                        • Anthony Jones

                          #13
                          Re: file size limit in Response.binary write

                          "Old Pedant" <OldPedant@disc ussions.microso ft.comwrote in message
                          news:85265E45-E160-4DE4-A613-E47DF74D5AD7@mi crosoft.com...
                          >
                          >
                          "S N" wrote:
                          >
                          >Just one clarification
                          >You intended
                          > For i = 1 To oStream.Size / clChunkSize
                          >or
                          > For i = 1 To oStream.Size \ clChunkSize
                          >
                          He *intended* the latter.
                          >
                          The backslash operator means "integer division" in VBScript (and VB and
                          VB.NET) code.
                          >
                          That is,
                          a \ b
                          is equivalent to
                          INT( a / b )
                          >
                          *************** *****
                          >
                          Also, you don't need to mess with Response.Buffer =False, at all.
                          >
                          Just follow each
                          Response.Binary Write
                          with
                          Response.Flush
                          >
                          Now the buffer will never get more full than one "chunkSize" .
                          >
                          Yes that would work. However it would mask unintended errors that turning
                          the buffer off right at the top of the code exposes.

                          --
                          Anthony Jones - MVP ASP/ASP.NET

                          Comment

                          • S N

                            #14
                            Re: file size limit in Response.binary write


                            "Anthony Jones" <AnthonyWJones@ yadayadayada.co mwrote in message
                            news:usmtyA4EJH A.1268@TK2MSFTN GP05.phx.gbl...
                            "Old Pedant" <OldPedant@disc ussions.microso ft.comwrote in message
                            news:85265E45-E160-4DE4-A613-E47DF74D5AD7@mi crosoft.com...
                            >>
                            >>
                            >"S N" wrote:
                            >>
                            >>Just one clarification
                            >>You intended
                            >> For i = 1 To oStream.Size / clChunkSize
                            >>or
                            >> For i = 1 To oStream.Size \ clChunkSize
                            >>
                            >He *intended* the latter.
                            >>
                            >The backslash operator means "integer division" in VBScript (and VB and
                            >VB.NET) code.
                            >>
                            >That is,
                            > a \ b
                            >is equivalent to
                            > INT( a / b )
                            >>
                            >************** ******
                            >>
                            >Also, you don't need to mess with Response.Buffer =False, at all.
                            >>
                            >Just follow each
                            > Response.Binary Write
                            >with
                            > Response.Flush
                            >>
                            >Now the buffer will never get more full than one "chunkSize" .
                            >>
                            >
                            Yes that would work. However it would mask unintended errors that turning
                            the buffer off right at the top of the code exposes.
                            >
                            --
                            Anthony Jones - MVP ASP/ASP.NET
                            >
                            >


                            what kind of errors would be exposed by turning off the buffer. kindly
                            elaborate.


                            Comment

                            • Anthony Jones

                              #15
                              Re: file size limit in Response.binary write

                              "S N" <uandme72@yahoo .comwrote in message
                              news:OYWSgZaFJH A.912@TK2MSFTNG P02.phx.gbl...
                              >
                              "Anthony Jones" <AnthonyWJones@ yadayadayada.co mwrote in message
                              news:usmtyA4EJH A.1268@TK2MSFTN GP05.phx.gbl...
                              >"Old Pedant" <OldPedant@disc ussions.microso ft.comwrote in message
                              >news:85265E4 5-E160-4DE4-A613-E47DF74D5AD7@mi crosoft.com...
                              >>>
                              >>>
                              >>"S N" wrote:
                              >>>
                              >>>Just one clarification
                              >>>You intended
                              >>> For i = 1 To oStream.Size / clChunkSize
                              >>>or
                              >>> For i = 1 To oStream.Size \ clChunkSize
                              >>>
                              >>He *intended* the latter.
                              >>>
                              >>The backslash operator means "integer division" in VBScript (and VB and
                              >>VB.NET) code.
                              >>>
                              >>That is,
                              >> a \ b
                              >>is equivalent to
                              >> INT( a / b )
                              >>>
                              >>************* *******
                              >>>
                              >>Also, you don't need to mess with Response.Buffer =False, at all.
                              >>>
                              >>Just follow each
                              >> Response.Binary Write
                              >>with
                              >> Response.Flush
                              >>>
                              >>Now the buffer will never get more full than one "chunkSize" .
                              >>>
                              >>
                              >Yes that would work. However it would mask unintended errors that
                              >turning the buffer off right at the top of the code exposes.
                              >>
                              >>
                              >
                              >
                              >
                              what kind of errors would be exposed by turning off the buffer. kindly
                              elaborate.
                              >
                              Well the sort of problems you've discovered where you may unintentionaly be
                              placing things in the output buffer that you didn't want present. Example:-

                              <!-- #include /virtual="/someinclude.asp " -->
                              <%
                              Response.Conten tType = "applicatio n/octet-stream"
                              Do Until ....
                              Response.Binary Write SomeStuff
                              Response.Flush
                              Loop
                              %>

                              'someinclude.as p

                              <!-- Ooops some accidental static content here -->
                              <%

                              'utility code

                              %>

                              Placing a Response.Buffer at the top of your page would barf immediately on
                              that line alerting you to a problem.
                              It also saves you having to remember to Response.Flush if you have multiple
                              places where you write to the buffer.

                              --
                              Anthony Jones - MVP ASP/ASP.NET

                              Comment

                              Working...