[Lazarus] Translating php://input into fcl-web

"Leonardo M. Ramé" l.rame at griensu.com
Sat Aug 23 23:40:54 CEST 2014


On 23/08/14 17:18, silvioprog wrote:
> On Sat, Aug 23, 2014 at 3:12 PM, "Leonardo M. Ramé" <l.rame at griensu.com
> <mailto:l.rame at griensu.com>> wrote:
>
>     Hi, I'm trying to translate this PHP code to fcl-web (actually
>     brookframework):
>
>     <?php
>     $content = file_get_contents('php://__input');
>     $fh = fopen('output.wav', 'w') or die("can't open file");
>     fwrite($fh, $content);
>     fclose($fh);
>     ?>
>
>     The difficult part is the line with
>     "file_get_contents('php://__input')", it contains the whole POST
>     content as binary.
>
>     What I already did was this:
>
>     procedure TActAudio.Post;
>     var
>        lWav: TMemoryStream;
>     begin
>        lWav := TMemoryStream.Create;
>        try
>          lWav.Write(HttpRequest.__Content[1], HttpRequest.ContentLength);
>          lWav.Position:= 0;
>          lWav.SaveToFile('/tmp/output.__wav');
>        finally
>          lWav.Free;
>        end;
>     end;
>
>     But the output.wav result is corrupt, while the php one is correct.
>
>     Any hint?.
>
>     Regards,
>
>
> Worked fine here:
>
> procedure TMyAction.Post;
> begin
>    with TFileStream.Create('out.txt', fmCreate) do
>    try
>      Write(TheRequest.Content[1], TheRequest.ContentLength);
>    finally
>      Free;
>    end;
> end;
>
> POST /cgi1.br <http://cgi1.br> HTTP/1.1
>
> {"key1":"value1","key2":"value2"}
>
> out.txt:
> {"key1":"value1","key2":"value2"}
>
> Or:
>
> procedure TMyAction.Post;
> begin
>    with TMemoryStream.Create do
>    try
>      Write(TheRequest.Content[1], TheRequest.ContentLength);
>      SaveToFile('post.txt');
>    finally
>      Free;
>    end;
> end;
>
> P.S.: php://input is not available with enctype="multipart/form-data".
>

Yes, with plain text everything works ok, the problem raises when I try 
to receive binary data, in this case a WAV file, enctype: "audio/x-wav".

The client (a Flash app running on the browser) is sending a POST 
message without params, just the binary data.


-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com




More information about the Lazarus mailing list