Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread How do download a file from a EWB server project?
Tue, Feb 13 2024 9:47 AMPermanent Link

Ralf Mimoun

Hi all,

I am sure that I am missing something, but I can't find anything in the forum.

I have a EWB server project that accepts a GET and sends some bytes back:

procedure TMainReqHandler.Download;
var
 Stream: TMemoryStream;
begin
 Stream := TMemoryStream.Create;
 try
   Stream.WriteUTF8String('test');
   Stream.Position := 0;
   CurrentRequest.SendCustomContentStream(Stream, 'application/pdf; charset=binary', 'binary', 'attachment; filename=test.pdf'); // ; charset=binary
 finally
   Sream.Free;
 end;
end;

It works - kinda. I get the corrent Content-Length from the server, and I see the bytes in the Chrome development tools, all of them, but I don't get a file in my download folder. I also get a HTTP OK/200. What am I missing?
Tue, Feb 13 2024 9:58 AMPermanent Link

Ralf Mimoun

I don't know if it's important, but I initate the GET request with a TServerRequest object in the client. All I set is it's URL property.
Wed, Feb 14 2024 1:07 PMPermanent Link

Ralf Mimoun

Problem solved: Using a ServerRequest simply does not work. Instead, I use window.open(URL,'_blank');. Now I have another problem but that's something for the next post.
Image