Re: [GXtilo] Upload de Imagenes

Conseguiste solucionar el problema?

Yo estoy en mismo caso con GxEv3.


El jueves, 20 de marzo de 2014 05:02:01 UTC+1, gab escribió:
Procedures as REST: Sending blob data as input to the procedure


This is the same example as Procedures as REST: Using SDT as input to the procedure, adding the way to send a blob variable data type as input to the Rest web service procedure.
The example consists of adding a customer to the Customer table, where there is a blob field representing the photo of the customer.

The "AddCustomer" procedure is the same as the one in the example Procedures as REST: Using SDT as input to the procedure.

The client consumer has the particularity that it has to do two HTTP POSTs:

1. An HTTP POST to "gxobject" (under the web application URL) attaching the file (blob) to the HTTP Request. This returns a reference which should be used to insert the blob in the database table.

2. Then execute an HTTP POST to the REST procedure sending a json request which includes the information to be processed.

Source Code of the GeneXus Client:

&httpclient.Host = &host //&httpclient is an HTTPClient variable data type  &httpclient.Port = &port  &httpclient.BaseUrl = &urlbase    //example:'/webappname/'     &httpclient.AddHeader('Content-type',' application/jpg ')  &httpclient.AddFile('CustomerPhoto.jpg')  &httpclient.Execute('POST','gxobject')     &lvc = &httpclient.ToString()  &blobref.FromJson(&lvc)  &ref = &blobref.object_id //&blobref is based on blobref data type (*)    &customersdt.CustomerId= &customerId  &customersdt.CustomerName = &customerName  &customersdt.Customerbirthdate = &customerbirthdate  &customersdt.CustomerPayDate = &customerPayDate  &customersdt.CustomerPhoto = &ref    &body = '{"Customersdt":' + &customersdt.ToJson() + '}'    //The following POST is to another BaseURL  &httpclient.BaseUrl = &urlbase + '/rest/'    //example: '/webappname/rest/'    &httpclient.AddHeader('Content-type','application/json')  &httpclient.AddString(&body)    &httpclient.Execute('POST','AddCustomer')

(*) blobref data type:

Image:blobrefdatatype

 

Then process the HTTP Client response.








Created: 03/16/11 04:32 PM by sjuarez Last update: 03/16/11 04:36 PM by sjuarez

--
Saludos,
gab
@gxsoft




On Fri, Nov 1, 2013 at 7:33 AM, Ramiro Galvan <ramiro.ga...@gmail.com> wrote:
Hola Matias, gracias por contestar... 

Justamente eso es lo que estoy haciendo, el problema que tengo es que lo tengo que ejecutar en un devices y no se como obtener la imagen para hacer el "&httpclient.AddFile('CustomerPhoto.jpg')"

Saludos


On Thu, Oct 31, 2013 at 10:20 PM, Matías Preciozzi <mprec...@gmail.com> wrote:
Hola Ramiro,

Esto te va a servir para subir imágenes al server.


Saludos,
Matias

Enviado desde mi iPhone

El 31/10/2013, a las 23:19, Ramiro Galvan <ramiro.ga...@gmail.com> escribió:

Hola, estoy tratando de sincronizar cambios en el devices sobre una transacción que tiene una foto y que quiero que, en el caso de cambiarla desde el dispositivo, se actualice en el server.

como seria la forma de hacer esto?  

Yo ya tengo la imagen en el sqlite y puedo obtener el path del archivo, aun así no logro subirlo. 

el addfile (supongo) me da este warning

Yo me fije como lo hacen las app conectadas (viendo el log del xcode) y vi que hacen el httpclient al objeto gxobject para subir la imagen al server, pero no puedo encontrar la forma de hacer el addfile (lo que no encuentro es la ruta que tengo que utilizar)

Oct 31 22:14:28 iPhone-de-Ramiro backboardd[28] <Warning>: Messenger[4860]: Could not stat /private/var/mobile/Applications/EB7F3EBF-A304-420C-96F3-5F9F508C0CAA/tmp/etilqs_ZAPVaVOSpGwhlpS: No such file or directory



---- ACA COPIO EL DODIGO QUE ESTOY USADO EN EL OBJETO QUE HACE EL SYNC


GetParameters.Call(&serverprotocol, &serverHost, &serverBaseURL, &serverRestBaseURL, &serverPort)


&SDT_Recurso = DPRecursoMod()


for &SDT_RecursoItem in &SDT_Recurso

&ref = ""

&sdt_recursofoto.recursofoto = &SDT_RecursoItem.RecursoFoto

&lvc = &sdt_recursofoto.ToJson()

&lvc = &lvc.Replace('recursofoto','path')

&lvc = &lvc.Replace('file://','')

&fileref.FromJson(&lvc)

&fotoref = &fileref.path

if not &SDT_RecursoItem.RecursoFoto.IsEmpty()

do "Subo Foto"

endif


&httpclient.Host = &serverHost.Trim()

//&httpclient.Port = &serverPort

&httpclient.BaseUrl = &serverRestBaseURL.Trim()

&SDT_Recurso2.recursoid = &SDT_RecursoItem.RecursoServerId

&SDT_Recurso2.recursofoto = &ref

&SDT_Recurso2.recursofotoref = &fotoref.Trim()

&SDT_Recurso2.recursotelefono = &SDT_RecursoItem.RecursoTelefono

&SDT_Recurso2.recursotelefonolaboral = &SDT_RecursoItem.RecursoTelefonoLaboral

&SDT_Recurso2.recursotelefonolaboralinterno = &SDT_RecursoItem.RecursoTelefonoLaboralInterno

&SDT_Recurso2.recursolinkedin = &SDT_RecursoItem.RecursoLinkedin

&SDT_Recurso2.recursogeolocation = &SDT_RecursoItem.RecursoGeolocation

&body = '{"SDT_Recurso2":' + &SDT_Recurso2.ToJson() + '}'

&httpclient.AddString(&body)

&httpclient.Execute(!'POST', !'ModRecurso')

If &httpclient.StatusCode = 201 

or  &httpclient.StatusCode = 200  //Success

&Respuesta = &httpclient.ToString() 

Do "ParsingJsonResult"

&RecursoEstado = EstadoSync.Sincronizado

else   //error 

&texto = &httpclient.ToString().Trim()

Do "ParsingJsonError"

&jsonmessages.FromJson(&texto)

&jsonmessage = &jsonmessages.error

&Message = new()

&Message.Id = &jsonmessage.Item(1).code

&Message.Type = MessageTypes.Warning

If not &jsonmessage.Item(1).message.IsEmpty()

&Message.Description = &jsonmessage.Item(1).message

else 

&Message.Description = &httpclient.GetHeader("Status Code")

endif

&Messages.Add(&Message)

&RecursoEstado = EstadoSync.Rechazado

endif


Do "UpdateREcurso"

endfor





Sub "ParsingJsonError"

/*This code converts this message:

{"error":{"code":"404","message":"Please enter a valid product quantity"}}

to:

{"error":[{"code":"404","message":"Please enter a valid product quantity"}]}

in order to load the SDT

*/

&texto = &texto.Replace('{"code"', '[{"code"')

&texto = &texto.Replace('"}}', '"}]}')

Endsub


sub "ParsingJsonResult"

//{"RecursoCatId":"45"}

&split = &Respuesta.SplitRegEx(':')  

&textmsg = &split.Item(2)

&textmsg = &textmsg.Replace('"','')

&RecursoCatId = &textmsg.ToNumeric()

endsub




sub "UpdateREcurso"

for each

where RecursoId = &SDT_RecursoItem.RecursoId

RecursoEstado = &RecursoEstado

endfor

endsub



sub "Subo Foto"


&httpclient.Host = &serverHost.Trim()

//&httpclient.Port = &serverPort

&httpclient.BaseUrl = &serverBaseURL.Trim()

&httpclient.AddHeader('Content-type',' application/jpg ')

&httpclient.AddFile(&fotoref)

&httpclient.Execute('POST','gxobject')

&lvc = &httpclient.ToString()

&blobref.FromJson(&lvc)

&ref = &blobref.object_id //&blobref is based on blobref data type (*)

endsub





Saludos y gracias

--
You received this message because you are subscribed to the Google Groups "GeneXus Tilo Beta Testers" group.
Visit this group at http://groups.google.com/a/genexus.com/group/gxtilo/.

To unsubscribe from this group and stop receiving emails from it, send an email to gxtilo+un...@genexus.com.

--
You received this message because you are subscribed to the Google Groups "GeneXus Tilo Beta Testers" group.
Visit this group at http://groups.google.com/a/genexus.com/group/gxtilo/.

To unsubscribe from this group and stop receiving emails from it, send an email to gxtilo+un...@genexus.com.

--
You received this message because you are subscribed to the Google Groups "GeneXus Tilo Beta Testers" group.
Visit this group at http://groups.google.com/a/genexus.com/group/gxtilo/.

To unsubscribe from this group and stop receiving emails from it, send an email to gxtilo+un...@genexus.com.

--
Has recibido este mensaje porque estás suscrito al grupo "GeneXus" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a genexus+unsubscribe@googlegroups.com.
Para acceder a más opciones, visita https://groups.google.com/d/optout.

0 Response to "Re: [GXtilo] Upload de Imagenes"

Publicar un comentario