Page 1 of 1
Subir una base.dbf a una carpeta en la nube
Posted: Fri Aug 20, 2021 5:32 pm
by acuellar
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/admconO poder abrirla desde la nube con una aplicación de escritorio.
Muchas gracias por la ayuda
Re: Subir una base.dbf a una carpeta en la nube
Posted: Fri Aug 20, 2021 6:31 pm
by Antonio Linares
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
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
Re: Subir una base.dbf a una carpeta en la nube
Posted: Mon Aug 23, 2021 5:39 pm
by acuellar
Estimado Antonio
Me podría pasar un ejemplo directo sin Modpro
No se como ejecutar la función de javascript
Gracias por la ayuda
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 6:21 am
by Antonio Linares
Adhemar,
Puedes llamar la función en javascript desde un botón, por ejemplo:
Code: Select all | Expand
function Main()
? [<button onclick="OpenDbf()">subir fichero</button>]
return nil
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 1:02 pm
by acuellar
Muchas Gracias Estimado Antonio
Lo he realizado así:
Code: Select all | Expand
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
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 3:14 pm
by Otto
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
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
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 4:50 pm
by acuellar
Thank you very much Mr. Otto. It works
Can you run the function directly if you need the button?
Thanks for the help
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 7:12 pm
by Otto
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
Re: Subir una base.dbf a una carpeta en la nube
Posted: Tue Aug 24, 2021 8:37 pm
by acuellar
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.
Re: Subir una base.dbf a una carpeta en la nube
Posted: Wed Aug 25, 2021 4:14 pm
by Otto
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
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
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
//----------------------------------------------------------------------------------------//
Re: Subir una base.dbf a una carpeta en la nube
Posted: Wed Aug 25, 2021 8:14 pm
by acuellar
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
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,
Re: Subir una base.dbf a una carpeta en la nube
Posted: Thu Sep 16, 2021 1:13 pm
by wilsongamboa
Adhemar C
buenos dias
me parece mas natural que uses hbnetio y leas directamente la tabla desde mod_harbour queda mas transparente
saludos
Wilson
Re: Subir una base.dbf a una carpeta en la nube
Posted: Thu Sep 16, 2021 5:57 pm
by acuellar
Muchas gracias estimado Wilson por el consejo
Podrías poner un ejemplo de como hacerlo con HBNETIO
Muchas gracias por la ayuda.
Re: Subir una base.dbf a una carpeta en la nube
Posted: Thu Sep 16, 2021 8:27 pm
by wilsongamboa
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.pdfcualquier duda a las ordenes
Wilson
Re: Subir una base.dbf a una carpeta en la nube
Posted: Thu Sep 16, 2021 9:58 pm
by acuellar
Muchas Gracias Estimado Wilson
Lo voy a intentar