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;
Code: Select all
return replyAsBinary(header,message);
Code: Select all
return header & message.String;
(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!