Web Connection
Is there a limit in Response.downloadFile()?
Gravatar is a globally recognized avatar based on your email address. Is there a limit in Response.downloadFile()?
  Abhay Sobti
  All
  May 3, 2022 @ 02:36am

Hi everyone,

I am using Response.downloadFile() to return PDF files to my users. Somehow, any PDF file larger than 5 MB is getting downloaded as a 1 Kb file. Look at the code below:

Code 1: 7 MB File, downloads only 1Kb 
Response.DownloadFile("D:\SHRDBMS\WEB\DOCUMENT\NV000177\NV000177_20211216_0001.PDF")

Code 2: 1 MB File, Downloads perfectly
Response.DownloadFile("D:\SHRDBMS\WEB\DOCUMENT\NV000177\NV000177_KYC.pdf")

What could I be doing wrong? Thanks in advance.

++ Abhay

Gravatar is a globally recognized avatar based on your email address. re: Is there a limit in Response.downloadFile()?
  Rick Strahl
  Abhay Sobti
  May 3, 2022 @ 05:12pm

Not for Web Connection. But IIS may limit the max response size if overridden in the IIS configuration.

There are two sets of settings that control this - one for IIS and one for ASP.NET.

IIS Setting

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483648" />
    </requestFiltering>
  </security>
</system.webServer>

The default value however should be much larger than 7mb. I never set this value and I've not seen any issues downloading file content of even very large files.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Is there a limit in Response.downloadFile()?
  Abhay Sobti
  Rick Strahl
  May 3, 2022 @ 11:22pm

Thanks Rick,

No, it is not an issue with IIS because, as you said, the web.config is setup for a very large value. The issue is with the Response.downloadFile() method. I changed the call to :

Response.transmitFile(m.cFileName,"text/html", JUSTFNAME(m.cFileName)

and the issue got resolved. The third parameter explicitly downloads the file at the client-end instead of opening it within the browser.

This got us through but looks like a revisit to the .downloadFile() is required as it is not using the third parameter at all and is using:

this.TransmitFile(lcFileName,lcContentType)

++ Abhay

Gravatar is a globally recognized avatar based on your email address. re: Is there a limit in Response.downloadFile()?
  Rick Strahl
  Abhay Sobti
  May 4, 2022 @ 10:25am

That doesn't make any sense if you say that the smaller files are working... It either works or it doesn't unless there's some sort of limit kicking in.

Web Connection doesn't have any response limits, and DownloadFile() actually just delegates to TransmitFile().

The reason DownloadFile() doesn't pass the filename is that it sets the same header that Transmit file sets. I guess in hindsight it might be easier to just call TransmitFile() with the parameter, but the way this evolved was these two actually had different implementations and then were combined.

I've simplified the code out like this:

************************************************************************
* wwPageResponse :: TransmitFile
****************************************
***  Function: Downloads a file to the client. The file is downloaded
***            directly from disk and not converted to a string.
***    Assume:
***      Pass: lcFilename      - the file to send
***            lcContentType   - content type string (image/jpeg)
***                              OR classic HTTP Header object (not recommended)
************************************************************************
FUNCTION TransmitFile(lcFileName, lcContentType, lcFileDisplayName)
LOCAL loHeader, lnSize

THIS.Clear()

IF EMPTY(lcFileName)
   lcFilename = ""  && causes IIS 404 response
ENDIF

IF VARTYPE(lcContentType) =  "C"
    IF !EMPTY(lcContentType)
       this.ContentType = lcContentType
   ENDIF
   lnSize = FileSize(lcFileName)
   this.Headers.Add("Content-Length",TRANSFORM(lnSize)) 

   IF !EMPTY(lcFileDisplayName)   
	   this.Headers.Add("Content-Disposition",[attachment; filename=]+ lcFileDisplayName )
   ENDIF
ELSE
   *** It's a header object
   loHeader = lcContentType   
   this.ContentTypeHeader(loHeader)
ENDIF


this.FastWrite("WC_TRANSMITFILE: " + lcFileName + CRLF)
this.End()
ENDFUNC
*  wwResponse :: TransmitFile


************************************************************************
* wwResponse :: DownloadFile
****************************************
***  Function: Downloads a file to the client using a FileOpen dialog
***    Assume:
***      Pass: lcFilename - the file to send
***            lcContentType   - wwHTTPHeader object 
***                         OR content type string (application/msword)
***            lcFileDisplayName - Name of the file to display to the user
***                                should be only a filename - no paths
************************************************************************
FUNCTION DownloadFile(lcFileName, lcContentType, lcFileDisplayName)
this.TransmitFile(lcFileName,lcContentType, lcFileDisplayName)
ENDFUNC
*  wwResponse :: DownloadFile

+++ Rick ---

© 1996-2024