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.r...@griensu.com
<mailto:l.r...@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.
As I cannot attach files here, please download this:
http://tempsend.com/6088747E14/DBFE/wami.tar.gz
That's an example for anyone to test, please uncompress and 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
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus