How can I send a MemoryStream to a cgi application ?

Hi,

I am using Tidhttp.post('www.host.com/my.cgi',Image_in_MemoryStream) to send an image to cgi application.
How can I put this image in a memory stream variable in the cgi application (my.cgi)?

Thanks
faustomenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

luwoCommented:

hi fausomen, maybe this works:

//1x idhttp-component,
//1x Memo-component

procedure TForm1.Button1Click(Sender: TObject);
var src,cont,tmp:Tmemorystream;
    ds,boundary:string;
    //helping procedure to write string with linefeed...
       procedure wr(const txt:string);
       var ds:string;
       begin
         ds:=txt+#13#10;
         src.Write(ds[1],length(ds));
       end;
begin

src  :=Tmemorystream.Create;
cont :=Tmemorystream.Create;


boundary:='---------------------------thisStringHasToBeUNIQUE';

//your http-content-type is multipart
idhttp1.Request.ContentType:='multipart/form-data; boundary='+boundary;

//the binary-file:
wr('--'+boundary);
wr('Content-Disposition: form-data; name="userfile"; filename="C:\originalfilename.bmp"');
wr('Content-Type: application/octet-stream');
wr('');

  //integrate the bin-data...
  tmp:=tmemorystream.Create;
  tmp.LoadFromFile('c:\binary.bmp');
  tmp.seek(0,0); src.CopyFrom(tmp,tmp.size);
  tmp.free;

wr(''); //last-linefeed is absolutely necessary!

//close your multipart...
wr('--'+boundary+'--');
wr('');

 IdHTTP1.Post('http://www.host.com/response.php?var1=content1',src,cont);

 cont.seek(soFromBeginning,0);
 memo1.Lines.LoadFromStream(cont);

src.free;
cont.free;
end;


//your response.php-file could be like this:
<?
$tmpfilename=$_FILES["userfile"][tmp_name];
$orgfilename=$_FILES["userfile"][name];

system('cp '.$tmpfilename.' /tmp/'.$orgfilename);

/*
the structure of _$FILES["blalaber"] is
Array
(
    [name] => testfile.zip
    [type] => application/x-zip-compressed
    [tmp_name] => /tmp/phppZxrmP
    [error] => 0
    [size] => 29868
)
*/
?>
---------------
hope, this is what r you searching for...

luwo
0
luwoCommented:
oh, i forgot, with the attached "?var1=content1" you are able to transfer data which could be easy transfered as strings...

another response.php-script:
------------------
<?
print "counts:<BR>\n-----------";
print sizeof($HTTP_POST_VARS) . "\n<HR><BR>";
print sizeof($HTTP_GET_VARS)   . "\n<HR><BR>";
print sizeof($HTTP_POST_FILES) . "\n<HR><BR>";
print "----------counts<BR>\n";


print "\n--------HTTP_POST_VARS------\n<BR>";
foreach ($HTTP_POST_VARS as $key => $value) echo "Schlüssel: $key; Wert: $value<br>\n";
print "\n--------HTTP_GET_VARS------\n<BR>";
foreach ($HTTP_GET_VARS as $key => $value) echo "Schlüssel: $key; Wert: $value<br>\n";
print "\n--------HTTP_POST_FILES------\n<BR>";
foreach ($HTTP_POST_FILES as $key => $value) echo "Schlüssel: $key; Wert: $value<br>\n";
?>

----------------------------
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
faustomenAuthor Commented:
Hi luwo,

I need to use a Delphi cgi application to receive image.
My client application is ready to send the image (using IdHTTP1.Post) but I dont know how to transfer the stream (from client application) to a variable MemoryStream in the cgi application.

Thanks


0
CleanupPingCommented:
faustomen:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
kacorretiredCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to accept luwo's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

kacor
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.