How put image inside Variant to Android (Java) and IOS (Objective C)

Hi, i have problems to put a image inside a list to send a petiton in a remoting ro server.

— C# is working well ----

     ServerAccess server = new ServerAcess();  
      List<AppImage> list = new List<AppImage();
        AppImage obj = new AppImage();
        byte[] imagen = File.ReadAllBytes(@"C:\imagenes\example.png");
        obj.Image = imagen;
       var result = server.Service1.SaveList(list);

– Android Java Problem —

imagenPedido.setTipoImagenPedidoID(1);
imagenPedido.setPedidoID(1);
VariantType data = new VariantType();
byte[] img = AlbumActivity.listaImagenes.get(i).getImagen();
data.setAsData(img);
imagenPedido.setImagen(data);
listaImagen.addItem(imagenPedido);

Error = java.lang.Exception: BinMessage : Unknown or unsupported variant type code

---- Objetive C ------

func guardarImagenes() {
let objeto = AppImagenPedido()
let lista = TAppImagenPedido()
let sesion = AppLogin()
let rovariant = ROVariant()
rovariant.asData = Datos.fotos[0].imagen as NSData
objeto.pedidoID = 1
objeto.tipoImagenPedidoID = 1
objeto.imagen = rovariant
lista?.add(objeto)
let respuesta = server.guardarFotos(lista!, sesion)
if (respuesta.Valida) {
print(“Correcto”)
}else{
print(“Error”)
}
}

Error = Error String “Unknown or unsupported type code 8209 found in variant stream”

I think your best option is to use the Binary type, for this.

I get Cannot Convert Byte[] to RemObjects.SDK.Types.Binary in c#

Hmm, can you show me more code? Binary is a distinct type from byte[]. but there should be methods to convert/create one from the other.

With Bynary in C# i trying… but i get error

System.Drawing.Image image = System.Drawing.Image.FromFile(@“C:\imagenes\example.png”);
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Png);
BinaryReader streamreader = new BinaryReader(stream);
obj.Imagen = new Binary(stream.ToArray());
lista.Add(obj);

Hmm, curious. This looks ok. I’m afraid I’ll have to defer this to my colleague. @antonk, any idea?

Hello

Which exactly error did you get? Binary is nothing more than a wrapper around MemoryStream, so anything that would work for MemoryStream would also work for Binary as well.

As for the original issue - could you show how exactly the server method is defined (both in RODL and in code)? What is the server platform (.NET or Delphi)?

Also could you point where exactly in the Java code you do perform a call to the server?

I tried the solution that they told me above but it worsened the solution in c #

the original problem is i cant set byte[] from a image to a data it is defined like variant in the RODL

in c# is working correctly.

byte[] imagen = File.ReadAllBytes(@"C:\imagenes\example.png");
        obj.Image = imagen;

but in java android and ios objective i have problems

– Android Java Problem —

imagenPedido.setTipoImagenPedidoID(1);
imagenPedido.setPedidoID(1);
VariantType data = new VariantType();
byte[] img = AlbumActivity.listaImagenes.get(i).getImagen();
data.setAsData(img);
imagenPedido.setImagen(data);
listaImagen.addItem(imagenPedido);

Error = java.lang.Exception: BinMessage : Unknown or unsupported variant type code

---- Objetive C ------

func guardarImagenes() {
let objeto = AppImagenPedido()
let lista = TAppImagenPedido()
let sesion = AppLogin()
let rovariant = ROVariant()
rovariant.asData = Datos.fotos[0].imagen as NSData
objeto.pedidoID = 1
objeto.tipoImagenPedidoID = 1
objeto.imagen = rovariant
lista?.add(objeto)
let respuesta = server.guardarFotos(lista!, sesion)
if (respuesta.Valida) {
print(“Correcto”)
}else{
print(“Error”)
}
}

Error = Error String “Unknown or unsupported type code 8209 found in variant stream”

could you show how exactly the server method is defined (both in RODL and in code)? What is the server platform (.NET or Delphi)?

Also could you point where exactly in the Java code you do perform a call to the server?

  public AppRespuestaGuardarImagenPedido GuardarImagenesPedidoBinary(AppImagenPedido[] ListaImagenes, AppLogin DatosLogin)
    {
        AppRespuestaGuardarImagenPedido res = new AppRespuestaGuardarImagenPedido();
        try
        {
         //...
        }
        catch (Exception ex)
        {
            res.Valida = false;
            res.Error = ex.Message;
        }
        return res;
    }
<Operation Name="GuardarImagenesPedido" UID="{F2E7A7A4-5087-4886-AD73-C2A927E0EE78}">
<Parameters>
<Parameter Name="Result" DataType="AppRespuestaGuardarImagenPedido" Flag="Result">
</Parameter>
<Parameter Name="ListaImagenes" DataType="TAppImagenPedido" Flag="In" >
</Parameter>
<Parameter Name="Login" DataType="AppLogin" Flag="In" >
</Parameter>
</Parameters>
</Operation>


<Struct Name="AppImagenPedido" UID="{D4F792CA-AC2B-4889-B8C3-3AC57D3FC7C1}" AutoCreateParams="1">
<Elements>
<Element Name="PedidoID" DataType="Integer">
</Element>
<Element Name="Imagen" DataType="Variant">
</Element>
<Element Name="TipoImagenPedidoID" DataType="Integer">
</Element>
</Elements>
</Struct>

You should use Binary data type to pass Binary data to server and back, not Variant

1 Like