Hi RTT
Thanks for sample. I play with it in few minutes.
I read many off post even when are out of my programing knowledge, give
me ideas how to do better my programs.
Thanks again to all ICS folks.
Xavi
Al 12/10/2010 18:55, En/na RTT ha escrit:
Here is a sample that work.
Get the 'multipart/form-data' encode tstream class code from this unit:
http://read.pudn.com/downloads116/sourcecode/internet/495621/Gz235_200671623235689/cn700_del549790557/IndyMultipartFormData/MsMultiPartFormData.pas__.htm
Start a new Delphi application, and in the main form place:
1 THttpCli,
1 TButton,
1 TMemo
1 TOpenDialog
function GetMimeType(fileName: string): string;
var reg: tregistry;
ext: string;
begin
result := 'application/unknown';
ext := lowercase(extractFileExt(filename));
reg := tregistry.Create;
try
reg.RootKey := HKEY_CLASSES_ROOT;
if reg.OpenKey(ext, false) and reg.ValueExists('Content Type')
then
result := reg.ReadString('Content Type')
finally
reg.Free;
end;
end;
procedure TForm1.UploadFile(url, Filename: string);
var
MultiPartFormDataStream: TMsMultiPartFormDataStream;
fStream: TFileStream;
begin
fStream := TFileStream.Create(Filename, fmOpenRead);
MultiPartFormDataStream := TMsMultiPartFormDataStream.create;
MultiPartFormDataStream.AddFile('fileupload1',
ExtractFileName(filename), GetMimeType(Filename), fstream);
fStream.free;
//there is a bug in the HFS code so we need to add a dummy field
here
MultiPartFormDataStream.AddFormField('fileupload2', '');
MultiPartFormDataStream.PrepareStreamForDispatch;
MultiPartFormDataStream.Position := 0;
Memo1.Lines.LoadFromStream(MultiPartFormDataStream);
MultiPartFormDataStream.Position := 0;
HttpCli1.ContentTypePost := 'multipart/form-data;
boundary='+MultiPartFormDataStream.Boundary;
HttpCli1.SendStream := MultiPartFormDataStream;
HttpCli1.URL := url;
HttpCli1.Post;
HttpCli1.SendStream.free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
UploadFile('http://81.184.21.22:100/hfs/', OpenDialog1.FileName);
end;
I have just now upload a file with this code to your HFS server.
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be
Se certifico que el correo entrante no contiene virus.
Comprobada por AVG - www.avg.es
Version: 9.0.862 / Base de datos de virus: 271.1.1/3192 - Fecha de la version:
10/12/10 08:34:00
--
Xavier Mor-Mur
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be