2
It is not possible to change this field because it is read-only due to security issues.
What you can do is send the file separately using the components of Indy, the TIdMultipartFormDataStream
and TIdHTTP
.
Uses
IdMultipartFormData, IdHTTP,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient;
//....
procedure EnviarArquivo(const URL, Campo, Arquivo: string);
var
IdHttp: TIdHTTP;
Parametros: TIdMultipartFormDataStream;
SS: TStringStream;
begin
IdHttp := TIdHTTP.Create(nil);
SS := TStringStream.Create();
try
Parametros := TIdMultipartFormDataStream.Create;
try
Parametros.AddFile(Campo, Arquivo);
try
IdHttp.Post(URL, Parametros, SS);
ShowMessage('Status: ' + IntToStr(IdHttp.ResponseCode));
except
on E: Exception do
ShowMessage('Post Error: ' + E.Message);
end;
Memo1.Text := SS.DataString;
finally
Parametros.Free;
end;
finally
IdHttp.Free;
SS.Free;
end;
end;
Use like this:
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
EnviarArquivo('<URL>', 'attachmentElement', '<CaminhoDoArquivo>');
end;
Can’t do what you want, because that property is read-only, how can you see here, see the item name, this is due to security issues.
– stderr
What you can do is send the file(s) separately using the
IdHTTP
.– stderr
zekk, can you give me an example of how to do this?
– Ronald