?
Solved

How can I send a MemoryStream to a cgi application ?

Posted on 2003-04-01
6
Medium Priority
?
410 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:faustomen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:luwo
ID: 8248459

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
 

Accepted Solution

by:
luwo earned 1000 total points
ID: 8248479
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
 

Author Comment

by:faustomen
ID: 8252870
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
 

Expert Comment

by:CleanupPing
ID: 9316505
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
 
LVL 10

Expert Comment

by:kacor
ID: 10041295
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question