Subir una base.dbf a una carpeta en la nube

mod_harbour es un módulo para Apache que permite correr tus PRGs directamente en la web!!!

Subir una base.dbf a una carpeta en la nube

Postby acuellar » Fri Aug 20, 2021 5:32 pm

Buenas estimados

Necesito subir una base.dbf que es actualizada por una aplicación de escritorio para luego mostrarla con Mod_Harbour
desde cualquier dispositivo

La dirección es:
http://190.171.250.71/admcon

O poder abrirla desde la nube con una aplicación de escritorio.

Muchas gracias por la ayuda
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Subir una base.dbf a una carpeta en la nube

Postby Antonio Linares » Fri Aug 20, 2021 6:31 pm

Adhemar,

En el ejemplo https://www.modharbour.org/modharbour_samples/modpro/modpro.prg usamos esta función en javascript
para seleccionar un DBF (opción "open" desde el menu) y enviarlo al servidor:

Code: Select all  Expand view
     function OpenDbf()
      {
        var oFile;
        oFPicker = document.createElement( "input" );
        oFPicker.type = "file";
        oFPicker.accept = ".dbf,.dbt,.fpt,.cdx,.ntx";
        oFPicker.style.visibility = "hidden";
        oFPicker.onchange = function( evt ){
           var reader = new FileReader();
           oFile = evt.target.files[0];
           reader.readAsDataURL( oFile );
           reader.onload = function( e ) {
               var formData = new FormData();
               var xhr = new XMLHttpRequest();
               var blob = new Blob( [e.target.result], {type: "application/octet-stream"} );
               formData.append( oFile.name, blob );
               xhr.onreadystatechange = function() {
                  if( this.readyState == XMLHttpRequest.DONE && this.status == 200 ) {
                     Command( this.responseText, true ); } };
            xhr.open( "POST", 'upload.prg' );
            xhr.send( formData );
           }
         };

        oFPicker.click();
      }


el fichero upload.prg se encarga de recibir el DBF y salvarlo en el servidor:
https://github.com/FiveTechSoft/mod_harbour/blob/master/samples/modpro/upload.prg
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Subir una base.dbf a una carpeta en la nube

Postby acuellar » Mon Aug 23, 2021 5:39 pm

Estimado Antonio

Me podría pasar un ejemplo directo sin Modpro
No se como ejecutar la función de javascript

Gracias por la ayuda
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Subir una base.dbf a una carpeta en la nube

Postby Antonio Linares » Tue Aug 24, 2021 6:21 am

Adhemar,

Puedes llamar la función en javascript desde un botón, por ejemplo:

Code: Select all  Expand view
function Main()

   ? [<button onclick="OpenDbf()">subir fichero</button>]

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Subir una base.dbf a una carpeta en la nube

Postby acuellar » Tue Aug 24, 2021 1:02 pm

Muchas Gracias Estimado Antonio

Lo he realizado así:
Code: Select all  Expand view

function Main()

   ? [<button onclick="OpenDbf()">subir fichero</button>]

return nil
*
Function OpenDbf()
      {
        var oFile;
        oFPicker = document.createElement( "input" );
        oFPicker.type = "file";
        oFPicker.accept = ".dbf,.dbt,.fpt,.cdx,.ntx";
        oFPicker.style.visibility = "hidden";
        oFPicker.onchange = function( evt ){
           var reader = new FileReader();
           oFile = evt.target.files[0];
           reader.readAsDataURL( oFile );
           reader.onload = function( e ) {
               var formData = new FormData();
               var xhr = new XMLHttpRequest();
               var blob = new Blob( [e.target.result], {type: "application/octet-stream"} );
               formData.append( oFile.name, blob );
               xhr.onreadystatechange = function() {
                  if( this.readyState == XMLHttpRequest.DONE && this.status == 200 ) {
                     Command( this.responseText, true ); } };
            xhr.open( "POST", 'upload.prg' );
            xhr.send( formData );
           }
         };

        oFPicker.click();
      }
Return
 

Y me sale éste error:

Error: Incomplete statement or unbalanced delimiters
operation: line:9
called from: HB_COMPILEFROMBUF, line: 0
called from: ..\source\exec.prg, EXECUTE, line: 68

Gracias por la ayuda
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Subir una base.dbf a una carpeta en la nube

Postby Otto » Tue Aug 24, 2021 3:14 pm

Adhemar,
Is OpenDBF() not a javascript function?

You have to tell mod harbour where HTML starts and end.

TEMPLATE
ENDTEXT

And inside HTML code, you have to tell the program where JavaScript starts and end.
<script></script>

Attention JavaScript is case sensitive Function does not work it must be function.

Best regards,
Otto
Code: Select all  Expand view



function Main()
   
    ? [<button onclick="OpenDbf()">subir fichero</button>]
   
    TEMPLATE
    <script>
        function OpenDbf()
        {
            var oFile;
            oFPicker = document.createElement( "input" );
            oFPicker.type = "file";
            oFPicker.accept = ".dbf,.dbt,.fpt,.cdx,.ntx";
            oFPicker.style.visibility = "hidden";
            oFPicker.onchange = function( evt ){
                var reader = new FileReader();
                oFile = evt.target.files[0];
                reader.readAsDataURL( oFile );
                reader.onload = function( e ) {
                    var formData = new FormData();
                    var xhr = new XMLHttpRequest();
                    var blob = new Blob( [e.target.result], {type: "application/octet-stream"} );
                    formData.append( oFile.name, blob );
                    xhr.onreadystatechange = function() {
                        if( this.readyState == XMLHttpRequest.DONE && this.status == 200 ) {
                            Command( this.responseText, true ); } };
                            xhr.open( "POST", 'upload.prg' );
                            xhr.send( formData );
                        }
                    };
                   
                    oFPicker.click();
                }
            </script>
        ENDTEXT
    Return
   
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: Subir una base.dbf a una carpeta en la nube

Postby acuellar » Tue Aug 24, 2021 4:50 pm

Thank you very much Mr. Otto. It works

Can you run the function directly if you need the button?

Thanks for the help
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Subir una base.dbf a una carpeta en la nube

Postby Otto » Tue Aug 24, 2021 7:12 pm

Adhemar,
I tried but get:
File chooser dialog can only be shown with a user activation.

I don't know if this is out of security reasons, possible.
Maybe with a workaround

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: Subir una base.dbf a una carpeta en la nube

Postby acuellar » Tue Aug 24, 2021 8:37 pm

Thanks Dear Otto.

What I need is to upload 3 specific files automatically. The desktop system user only has to click on the link and return a "READY" message. And if possible, run the link from the desktop application.

Thank you very much for the help.
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Subir una base.dbf a una carpeta en la nube

Postby Otto » Wed Aug 25, 2021 4:14 pm

Ademar,
I think that's difficult for security reasons.
I did some tests today.
What I managed to do is to send a txt or json file.
I exported the DBF file to TXT and json-encoded the file.

I read the TXT file into a variable, and then I make a FORMDATA object that I upload with AJAX.

At the backend, you then have the entire harbor scope and can format the result.

Besst regards,
Otto

upload.prg

Code: Select all  Expand view

function main()

TEMPLATE
<!doctype html>
<html lang="en">
<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>Ihre Anmeldung</title>
</head>

<body>
  <script src="assets/js/jquery.min.js"></script>
  <script src="assets/bootstrap/js/bootstrap.min.js"></script>
  <script>

var allText ="";
function readTextFile(file)
{
    var rawFile = new XMLHttpRequest();
    rawFile.open("GET", file);
    rawFile.onreadystatechange = function ()
    {
        if(rawFile.readyState === 4)
        {
            if(rawFile.status === 200 || rawFile.status == 0)
            {
                 allText = rawFile.responseText;
            }
        }
    }
    rawFile.send(null);
}

//var file ="newfile.txt";
var file ="customer.json";

readTextFile( file );

$( document ).ready(function() {
    console.log( "ready!" );
   
    var fd = new FormData();
    fd.append('data',allText);

    $.ajax({
    type: "post",
    url: "https://test.com/modharbour_samples/data.prg",
    data: ( fd ),
    contentType: false,
              processData: false,
    success: function(response) {
        console.log(response);
    }
});
   
});

  </script>
 
</body>

</html>
ENDTEXT

return NIL

//----------------------------------------------------------------------------------------//
 



data.prg

Code: Select all  Expand view


REQUEST DBFCDX
REQUEST DBFFPT

function main()
    local hPairs := AP_Body()
    local hdata := {=>} 

    cLog := ValToChar( hPairs ) + CRLF
    MEMOWRIT("c:\www\htdocs\modharbour_samples\log.log" , cLog, .f. )

    hData['error'] := 'true'
   
    AP_SetContentType( "application/json" )
   
    ?? hb_jsonEncode( hdata, .T. )  // T=pretty
   
return NIL

//----------------------------------------------------------------------------------------//


 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: Subir una base.dbf a una carpeta en la nube

Postby acuellar » Wed Aug 25, 2021 8:14 pm

Thank you very much dear Otto

I did it by installing Apache24 on the client and FTP on the server.
With in the program: ftpup.prg.

I run it with:
Code: Select all  Expand view

Function ActulizaFTP()
Local oHttp

oHttp := CreateObject( "winhttp.winhttprequest.5.1" )

oHttp:Open("GET","http://localhost/admcon/ftpup.prg", .f. )
oHttp:Send()

Return
 


Thanks for your time and help.

Regards,
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Subir una base.dbf a una carpeta en la nube

Postby wilsongamboa » Thu Sep 16, 2021 1:13 pm

Adhemar C
buenos dias
me parece mas natural que uses hbnetio y leas directamente la tabla desde mod_harbour queda mas transparente
saludos
Wilson
Wilson 'W' Gamboa A
Wilson.josenet@gmail.com
User avatar
wilsongamboa
 
Posts: 548
Joined: Wed Oct 19, 2005 6:41 pm
Location: Quito - Ecuador

Re: Subir una base.dbf a una carpeta en la nube

Postby acuellar » Thu Sep 16, 2021 5:57 pm

Muchas gracias estimado Wilson por el consejo

Podrías poner un ejemplo de como hacerlo con HBNETIO

Muchas gracias por la ayuda.
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia

Re: Subir una base.dbf a una carpeta en la nube

Postby wilsongamboa » Thu Sep 16, 2021 8:27 pm

Buenas tardes
hace tiempo hice un pdf donde se explica todo esto, pensando mostrarlo en las charlas de mod_harbour no se como subirlo aca
lo puedes bajar de
http://186.4.197.203/ift/hbnetio.pdf
cualquier duda a las ordenes
Wilson
Wilson 'W' Gamboa A
Wilson.josenet@gmail.com
User avatar
wilsongamboa
 
Posts: 548
Joined: Wed Oct 19, 2005 6:41 pm
Location: Quito - Ecuador

Re: Subir una base.dbf a una carpeta en la nube

Postby acuellar » Thu Sep 16, 2021 9:58 pm

Muchas Gracias Estimado Wilson

Lo voy a intentar
Saludos,

Adhemar C.
User avatar
acuellar
 
Posts: 1593
Joined: Tue Oct 28, 2008 6:26 pm
Location: Santa Cruz-Bolivia


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 9 guests