I am trying to find an example how to put a file (jpeg image) into a website using TNetHTTPClient but no luck.

I am trying to find an example how to put a file (jpeg image) into a website using TNetHTTPClient but no luck. I found no Delphi samples about this.
If someone has a simple sample or point a solution I would appreciate.
UPDATE: I was able to get and modify a routine able to upload file, but the server side is PHP and requires a variable with the filename. I really don't know how to set that var and value to make it work. So far the routine I did is:

Procedure UploadFile(HttpClient: TNetHTTPClient; const URL: string; const FullFilename: string);
var
LMultipartFormData: TMultipartFormData;
begin
LMultipartFormData := TMultipartFormData.Create;
try LMultipartFormData.AddFile(ExtractFileName(FullFilename), FullFilename);
HttpClient.ContentType := 'multipart/form-data';
HttpClient.Post(URL, LMultipartFormData);
finally
LMultipartFormData.Free;
end;
end;

Maybe using LMultipartFormData.AddField() would solve, I even tried to put something there but not worked.

Comments