I need to transfer images from Android to the Server, tried the code below but is giving the error, I use Delphi Berlin:
Exception class EJNIException with message 'java.net.SocketException: sendto failed: EPIPE (Broken pipe)'.
Client side (Android)
I remember the photo is saved in sqllite.
procedure TDM.EnviaImagens;
var
Fdq: TFDQuery;
I: Integer;
BS: TStream;
cod: String;
begin
Fdq := TFDQuery.Create(Self);
Fdq.Connection := FreteappliteConnection;
Fdq.SQL.Clear;
Fdq.SQL.Add('select viagem, imagem from fotos');
Fdq.Open;
Fdq.First;
if Fdq.RecordCount > 0 then
begin
for I := 0 to Fdq.RecordCount - 1 do
begin
Fdq.Edit;
BS := Fdq.CreateBlobStream(Fdq.FieldByName('imagem'), bmReadWrite);
cod := TNetEncoding.Base64.EncodeBytesToString(BS, BS.Size);
if not(ModuloCliente.SrvServerMetodosClient.AgroInsereFotos
(Fdq.FieldByName('viagem').AsInteger, cod) = True) then
begin
BS.Free;
Fdq.Free;
exit
end
else
begin
Fdq.Next;
BS.Free;
end;
end;
end;
end;
On the Server side I have the following code:
function TSrvServerMetodos.AgroInsereFotos(Viagem: Integer;
Foto: String): Boolean;
var
Fdq: TFDQuery;
BS: TStream;
begin
Result := False;
try
BS := TBytesStream.Create(TNetEncoding.Base64.DecodeStringToBytes(Foto));
Fdq := TFDQuery.Create(Self);
Fdq.Connection := FDConnection;
Fdq.SQL.Clear;
Fdq.SQL.Add
('insert into Agropecuaria_Viagens_Fotos (codigo, viagem, foto) values (:codigo, :viagem, :foto)');
Fdq.ParamByName('codigo').AsInteger := Random(10);
Fdq.ParamByName('viagem').AsInteger := Viagem;
Fdq.ParamByName('foto').AsStream := BS;
Fdq.ExecSQL;
Fdq.Free;
BS.Free;
Result := True;
Except
Result := False;
Fdq.Free;
BS.Free;
end;
end;