这与我之前的问题here有关,我发现了一个东西,认为这可能是解决我的问题的方法,但我无法让它工作,我需要有人谁可以帮助我。
这是密码
代码TIdMIMEBoundary.FindBoundary()的问题是未声明的标识符和Fetch()。
uses
...
IdTCPConnection, IdTCPClient, IdHTTP, IdBaseComponent,
IdComponent, IdCustomTCPServer, IdCustomHTTPServer, IdHTTPServer,
IdContext, IdMultipartFormData, IdHeaderList, IdMessageCoder,
IdMessageCoderMIME, IdMessage, IdGlobalProtocols;
procedure DecodeFormData(const Header: String; ASourceStream:TStream);
var
MsgEnd: Boolean;
Decoder: TIdMessageDecoder;
Tmp: String;
Dest: TStream;
begin
MsgEnd := False;
Decoder := TIdMessageDecoderMIME.Create(nil);
try
TIdMessageDecoderMIME(Decoder).MIMEBoundary :=
TIdMIMEBoundary.FindBoundary(Header);
Decoder.SourceStream := ASourceStream;
Decoder.FreeSourceStream := False;
Decoder.ReadLn;
repeat
Decoder.ReadHeader;
case Decoder.PartType of
mcptUnknown:
raise Exception.Create('Unknown form data detected');
mcptText:
begin
Tmp := Decoder.Headers.Values['Content-Type'];
Dest := TMemoryStream.Create;
try
Decoder := Decoder.ReadBody(Dest,MsgEnd);
if AnsiSameText(Fetch(Tmp, ';'),'multipart/mixed') then
DecodeFormData(Tmp, Dest)
else
// use Dest as needed...
finally
FreeAndNil(Dest);
end;//try
end;
mcptAttachment:
begin
Tmp := ExtractFileName(Decoder.FileName);
if Tmp <>'' then
Tmp := 'c:\some folder\' + Tmp
else
Tmp := MakeTempFilename('c:\somefolder\');
Dest := TFileStream.Create(Tmp, fmCreate);
try
Decoder := Decoder.ReadBody(Dest,MsgEnd);
finally
FreeAndNil(Dest);
end;//try
end;
end;
until (Decoder = nil) or MsgEnd;
finally
FreeAndNil(Decoder);
end;//try
end;
字符串
2条答案
按热度按时间0g0grzrc1#
您需要在uses子句中包含IdMessage和IdMessageCoderMIME
vojdkbi02#
我创建了一个名为
TIdMultiPartFormDataStreamReader
的对象,它可以在一个步骤中解码您在服务器上接收到的所有多部分/表单数据内容。字符串
项目在https://github.com/enriquecerda/TIdMultiPartFormDataStreamReader中