Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How can I send a MemoryStream to a cgi application ?

Posted on 2003-04-01
6
Medium Priority
?
422 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
5 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses

577 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