Recent

Author Topic: [Solved] Missing "CR" when download file from fpweb embedded server  (Read 666 times)

eolandro

  • New Member
  • *
  • Posts: 14
Hi!
I have a simple webserver for download files. it use TFPWebModule but when i download a binary file some chars are stripped ("CR"  => '\r'). My DataModuleRequest have code like this:
Code: Pascal  [Select][+][-]
  1. if ARequest.URI = '/down' then
  2.    begin
  3.      AResponse.ContentType:= 'application/octet-stream';
  4.      AResponse.Contents.LoadFromFile(ARequest.ContentFields.Values['FL']);
  5.    end;                          
  6.  
i have tested with curl and python. but all "CR" are missing

i changed my code to:
Code: Pascal  [Select][+][-]
  1. if ARequest.URI = '/down' then
  2.    begin
  3.      AResponse.ContentType:= 'application/octet-stream';
  4.      MS := TMemoryStream.Create;
  5.      MS.LoadFromFile(ARequest.ContentFields.Values['FL']);
  6.      AResponse.ContentStream.CopyFrom(MS,MS.Size);
  7.    end;                          
  8.  
But does not work.

Any suggestions?

PD. sorry for bad english.
« Last Edit: October 21, 2022, 08:27:18 pm by eolandro »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8744
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Missing "CR" when download file from fpweb embedded server
« Reply #1 on: October 17, 2022, 06:49:36 pm »
TResponse.Contents is a TStrings descendant. It uses OS native line ending by default. TResponse has another property, ContentStream, which can be used for binary transfer. So use that instead.

eolandro

  • New Member
  • *
  • Posts: 14
Re: [Solved] Missing "CR" when download file from fpweb embedded server
« Reply #2 on: October 21, 2022, 08:28:40 pm »
Yes, thanks so much!

Now this code works
Code: Pascal  [Select][+][-]
  1. if ARequest.URI = '/down' then
  2.    begin
  3.      AResponse.ContentType:= 'application/octet-stream';
  4.      MS := TMemoryStream.Create;
  5.      MS.LoadFromFile(ARequest.ContentFields.Values['FL']);
  6.      AResponse.ContentStream := MS;
  7.    end;                          
  8.  

 

TinyPortal © 2005-2018