Board index » delphi » How can I accept files via form to my Indy HTTP server?
Reiner
![]() Delphi Developer |
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; |