FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index mod_harbour Subir una base.dbf a una carpeta en la nube
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Subir una base.dbf a una carpeta en la nube
Posted: Fri Aug 20, 2021 05: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.
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Fri Aug 20, 2021 06: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 (fw): Select all Collapse
 聽 聽 聽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
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Mon Aug 23, 2021 05: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.
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 06:21 AM
Adhemar,

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

Code (fw): Select all Collapse
function Main()

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

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 01:02 PM
Muchas Gracias Estimado Antonio

Lo he realizado as铆:
Code (fw): Select all Collapse
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.
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 03: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 (fw): Select all Collapse
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
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 04: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.
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 07: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

Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 08: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.
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Wed Aug 25, 2021 04: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 (fw): Select all Collapse
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 (fw): Select all Collapse
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

//----------------------------------------------------------------------------------------//
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Wed Aug 25, 2021 08: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 (fw): Select all Collapse
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.
Posts: 670
Joined: Wed Oct 19, 2005 06:41 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Thu Sep 16, 2021 01: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
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Thu Sep 16, 2021 05: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.
Posts: 670
Joined: Wed Oct 19, 2005 06:41 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Thu Sep 16, 2021 08: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
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Subir una base.dbf a una carpeta en la nube
Posted: Thu Sep 16, 2021 09:58 PM

Muchas Gracias Estimado Wilson

Lo voy a intentar

Saludos,



Adhemar C.

Continue the discussion