Board index » delphi » How can I accept files via form to my Indy HTTP server?

How can I accept files via form to my Indy HTTP server?


2003-10-20 02:00:28 PM
delphi131
How can you decode the TIdHTTPRequestInfo when a form file (input
type="file") is used?
I have hunted high and low (on Google web and groups) on how to do this and
spent a few hours trying demo projects using things like
TIdMessageDecoderMIME (see code below) to no avail.
Basically the server gets the data and I can see it encoded in
TIdHTTPRequestInfo.UnparsedParams but I can not easily do something with it. I
have posted a sample form, and the data that I get when I upload a file, in
the attachments group.
"form upload files"
As mentioned above, I have tried decoding this using Indy tools, including
the following code (which incidentally gets into an infinite loop inside
Indy as it fails to handle the end of the stream properly). The following
creates a stream from a selected file.
--
procedure TForm1.Button3Click(Sender: TObject);
var
decoder, temp : TIdMessageDecoderMIME;
outfstream : TFileStream;
filename : string;
idx : integer;
isend : boolean;
begin
idx := 1;
decoder := TIdMessageDecoderMIME.Create(Self);
try
filename := OpenDialog.FileName;
{ open stream }
decoder.SourceStream := TFileStream.Create(filename, fmOpenRead or
fmShareDenyWrite);
decoder.MIMEBoundary := TIdStream(decoder.SourceStream).ReadLn;
decoder.SourceStream.Position := 0;
while Assigned(decoder) do
begin
filename := Copy(filename, 1, LastDelimiter('.', filename)-1) +
IntToStr(idx) + '.msg';
outfstream := TFileStream.Create(filename, fmCreate or
fmShareDenyWrite);
try
temp := TIdMessageDecoderMIME(decoder.ReadBody(outfstream, isend));
finally
FreeAndNil(decoder);
outfstream.Free;
end;
decoder := temp;
inc(idx);
end;
finally
if Assigned(decoder) then
decoder.Free;
end;
end;
 
 

Re:How can I accept files via form to my Indy HTTP server?

Never mind I guess since I wrote my own unit to decode it. Obviously hardly
anyone has the need to do this.
Is anyone actually running a real Indy web server or am I the only one?
"Reiner" <XXXX@XXXXX.COM>writes
Quote
How can you decode the TIdHTTPRequestInfo when a form file (input
type="file") is used?
 

Re:How can I accept files via form to my Indy HTTP server?

"Reiner" <XXXX@XXXXX.COM>writes
Quote
Never mind I guess since I wrote my own unit to decode it. Obviously
hardly
anyone has the need to do this.

Is anyone actually running a real Indy web server or am I the only one?

There are at leaset two of us, though mine are all on intranets.
What is 'files via form'??
Rgds,
Martin
 

Re:How can I accept files via form to my Indy HTTP server?

"Reiner" <XXXX@XXXXX.COM>writes
Quote
Is anyone actually running a real Indy web server
or am I the only one?
Sure, many people are (they are not necessary here in the groups, but they
are out there in the real world). But uploading files via HTTP is not
necessary a common practice. Although HTTP can upload files to a server,
the server has to be able to accept such transfers. FTP handles the scenrio
must better, and in fact most web servers do use FTP to upload files with
instead.
Gambit
 

Re:How can I accept files via form to my Indy HTTP server?

"Martin James" <XXXX@XXXXX.COM>writes
Quote
There are at leaset two of us, though mine are all on intranets.
I'm running a public server with about 5 domains{*word*154} off it and also and
FTP server.
Quote
What is 'files via form'??
If you have a HTML form and put the following field type in:
<form action="cgi-bin/getfile" enctype="multipart/form-data" method="post">
<input type="file" name="afile">
</form>
What happens is the server receives the file in the RequestInfo but there's
nothing to decode it.
 

Re:How can I accept files via form to my Indy HTTP server?

"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote
But uploading files via HTTP is not
necessary a common practice. Although HTTP can upload files to a server,
the server has to be able to accept such transfers. FTP handles the
scenrio
must better, and in fact most web servers do use FTP to upload files with
instead.
If you have a web site where you invite visitors to upload their own
pictures and comments, for example, you need a form to handle file uploads.
I wish to create this sort of thing on my server. Webmail software also
needs this sort of thing to handle attachments. FTP is not suitable for this
sort of thing. Indy does get the information/files in
RequestInfo.UnparsedParams but it can not be decoded (by any of the tools I
found). It took me half a day but I now have something that decodes it for
me.