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

"Leonardo M. Ramé" l.rame at griensu.com
Sun Aug 24 01:01:47 CEST 2014


On 23/08/14 18:40, "Leonardo M. Ramé" wrote:
> 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.
>
>
I made an example using fcl-web (without Brook) and the problem persists.

I attached an example for anyone to test, please, copy the following 
files to your apache documents folder (/var/www/html on Ubuntu):

testwami.html
swfobject.js
wamirecorder.js

Also please download the file Wami.sfw from here: 
https://wami-recorder.googlecode.com/hg/example/client/Wami.swf and copy 
to the same folder as the previous files. I cannot attach it here 
because of email size restrictions of the mailing list.

Also please compile the project cgiproject.lpi contained in wami.tar.gz, 
then copy the executable to your /cgi-bin/ directory.


Regards,

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: wami.tar.gz
Type: application/gzip
Size: 8115 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140823/a45949cd/attachment-0001.gz>


More information about the Lazarus mailing list