Issues with replyAsBinary() method in jadeHTMLClass

For questions and postings not covered by the other forums
timmeh
Posts: 18
Joined: Fri Apr 13, 2012 3:12 pm

Issues with replyAsBinary() method in jadeHTMLClass

Postby timmeh » Fri Apr 13, 2012 3:30 pm

Hi,

I've been trying to get this method to work for me but keep running into the same weird issue.

I follow the documentation and re-implement generateHTMLString(), add the code to convert a file to binary, when I click a link to download the file
it works, downloads first time. Then after the first response all other requests receive no response, the server stops replying until i restart the application although
no exceptions are logged.

Below is the code:

Code: Select all

generateHTMLString(): String updating; vars downloadFile : File; message : Binary; header : String; begin //checks if the request should initiate file download if getHttpValue("downloadFile") = "file" then create downloadFile transient; downloadFile.fileName := 'c:/test/test.pdf'; downloadFile.kind := downloadFile.Kind_Binary; downloadFile.mode := File.Mode_Input; downloadFile.open; message := downloadFile.readBinary(downloadFile.fileLength); downloadFile.close; header := 'HTTP/1.1 200 OK' & CrLf & 'Content-Type: ' & 'application/pdf' & CrLf & downloadFile.fileName & CrLf & 'Content-Disposition: attachment;filename=' & downloadFile.fileName & CrLf & 'Content-Length: ' & message.length.String & CrLf & CrLf; return replyAsBinary(header,message); endif; epilog delete downloadFile; end;
if I change

Code: Select all

return replyAsBinary(header,message);
to

Code: Select all

return header & message.String;
The file downloads, yet when I open it its corrupt, although the webserver still works and I can still navigate throughout the website.
(I read in the documentation that the header is UTF8 and the binary isnt? Not sure if this has some effect)

Any suggestions would be greatly appreciated, this has got me really stuck!

kpd
Posts: 3
Joined: Wed Oct 20, 2010 1:11 pm

Re: Issues with replyAsBinary() method in jadeHTMLClass

Postby kpd » Mon May 28, 2012 10:03 am

Timmeh,

We have recently experienced problems with using replyAsBinary as well, that are related to the IIS version we are running with. The recommended header code that you are using is fine when using IIS 6, but if you are running with IIS 7 or 7.5, then you need to remove the HTTP/1.1 line from the header string. i.e. change your code to

Code: Select all

header := 'Content-Type: ' & 'application/pdf' & CrLf & downloadFile.fileName & CrLf & 'Content-Disposition: attachment;filename=' & downloadFile.fileName & CrLf & 'Content-Length: ' & message.length.String & CrLf & CrLf;
and it will work regardless of the IIS version.

Cheers,
Kevin Douglas

timmeh
Posts: 18
Joined: Fri Apr 13, 2012 3:12 pm

Re: Issues with replyAsBinary() method in jadeHTMLClass

Postby timmeh » Thu Jun 14, 2012 2:48 pm

Thanks! That was really helpful for a recent upgrade, my original issue was i didnt reimplement some of the other classes replyAsBinary required

M45HY
Posts: 63
Joined: Wed Jul 11, 2012 7:32 am
Location: Mansfield, Nottinghamshire, UK

Re: Issues with replyAsBinary() method in jadeHTMLClass

Postby M45HY » Wed Jan 15, 2014 2:16 am

Hi Everyone,

I've come across the same problem that timmeh was initialling coming across and I'm unable to fix it. I believe the problem is where the system is using the replyAsBinary method. At the moment, when I use replyAsBinary, it makes a file downloadable but then the browser stops responding (we are using JADE generated HTML but will be moving to Web Services but for the short term, we still need to get this working for existing clients).

Once the Windows dialog box appears/closes (Open/Save/Close) the user has to refresh the web page (F5) and then the system starts to respond. I was wondering whether someone could tell me how to reimplement the replyAsBinary method, just in case that's the solution or whether there is another method I could use instead of replyAsBinary?

Thanks,
Omash
"If you can't explain it simply, you don't understand it well enough." - Albert Einstein


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 13 guests

cron