0

Well I solved the problem of running out of memory when accessing the PDF files, but now it seems that when I try to access big files via Chrome or Firefox I get gibberish. It doesn't open Adobe, it just display it as a page with millions of characters. Im using the code below to get it to the user, any ideas on why it would be doing this?

case "PDF":
     context.Response.ContentType = "application/pdf";
     context.Response.AddHeader("content-disposition", "inline; filename=" + asset.A_Name);
}

context.Response.BinaryWrite(content);
atrljoe
  • 8,031
  • 11
  • 67
  • 110

2 Answers2

4

You have to add a content length header to the response. Its a problem with IIS chunked encoding. Look here.

context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());

Community
  • 1
  • 1
coder net
  • 3,447
  • 5
  • 31
  • 40
  • I implemented this, and it works for some of my PDFs, but it seems that large ones are still displaying the gibberish. You have any idea what would cause this? I also tried adding the `Response.Clear()` before my switch and it does nothing. – atrljoe Jul 25 '11 at 14:52
  • does it work in IE? also try setting Response.Buffer = false. – coder net Jul 25 '11 at 15:50
  • I tried adding the buffer, and that did nothing. It does work in IE, but no other browsers. Thanks for your help so far, you have any other ideas? – atrljoe Jul 25 '11 at 16:55
  • I'm not sure. It seems to work for me. How large is the file.. Also, is it possible to try Response.TransmitFile and see? – coder net Jul 25 '11 at 17:06
  • I am using `BinaryWrite`. well after checking the file size I noticed that it doesn't do this on files less than 10MB in size. What would cause that? This has me even more perplexed on whats going on. – atrljoe Jul 25 '11 at 17:07
  • It sounds to me like FF/Chrome are ignoring the settings and still trying to set a buffer size of 10MB. Can you try Response.TransmitFile and see if there is any difference? Also see this link http://www.eggheadcafe.com/microsoft/IIS-ASP/33531854/response-buffer-limit-exceeded.aspx – coder net Jul 25 '11 at 17:10
  • ***Chrome and Android*** - *Android 4, Ice Cream Sandwich*. Example: `Content-Disposition: attachment; filename="MyFileName.ZIP";` will not work correctly because of the semicolon at the end. Any tests (and _summary_) for all Android versions ? Useful: http://stackoverflow.com/questions/6319389/streaming-mime-type-application-pdf-from-asp-app-fails-in-google-chrome `Google Chrome v12 release introduced a bug that triggers the problem you describe. You can fix it by sending the Content-Length header` https://bugs.chromium.org/p/chromium/issues/detail?id=85549 – Kiquenet Jan 25 '17 at 15:43
0

Has anything already been written to the Response stream? Make sure to call Response.Clear() first.

GalacticCowboy
  • 11,663
  • 2
  • 41
  • 66