LocalFileToVar command - Forum

Forum Navigation
You need to log in to create posts and topics.

LocalFileToVar command

I played around with the LocalFileToVar command.

Some observations and suggestions.

a) The properties of the "fileinput obj name" named "initial-value" and "property-name" do not appear to have any significance. Each time I invoke this Button (in the Chrome Browser), it presents a FileOpen Dialog Box that shows the files in the Downloads folder (with nothing in the File Name box).

This behavior is the same as the <input type="file" name="myFile"> example in the w3schools website.

Is there any way to ...

- specify an initial folder ?
- pre-populate the File Name Box ?

b) It is very important to take note of the phrase in the Help file that "loading is asynchronous"; this is similar to making get/put requests to a server (meaning that this command does NOT wait for the file content to be loaded into the specified variable). My observation was that commands coded after this command (in my case AlertBox) do not even get serviced.

You can see when the content is loaded by associating the receiving variable with a Container object.

So, I tried to use the "Watch" command ... unfortunately, I could not get the specified subroutine to be triggered.

Can there be a way of allowing the developer to specify commands to be serviced upon the completion of the LocalFileToVar event ...

- either with an event section in the Button object
- or a third parameter in the command that specifies the subroutine to be invoked (similar to AlertBox)

Hi Gaev,

For any reason, Watch command doesn't work when activated from the button, but it works fine if it is activated from Project Events or page-enter event.

Please take a look at the attached file.
Anyway, as most of the file operations are asynchronous I will try top add a new parameter to call a subroutine when finished.

Thank you!

Uploaded files:
  • You need to login to have access to uploads.

@luishp:

Please take a look at the attached file.

For any reason, Watch command doesn't work when activated from the button, but it works fine if it is activated from Project Events or page-enter event.

Thanks; the revised sample app worked just fine. I sent you an email about this limitation.

Anyway, as most of the file operations are asynchronous I will try top add a new parameter to call a subroutine when finished.

Thanks; this will add even more value to the product.

Regarding point a) please take a look at this other thread.

The property property-name is mandatory, otherwise the FileInput Object will not work.
Please take a look here.

Thank you.

@luishp:

Thank you, but my point was about "a possible way (via variables) to pre-set the initial Folder and File in the FileOpen Dialog Box that the user is presented with".

As I mentioned in the other post, the example on the w3schools website exhibited similar behaviour; and a Google search shows that other have asked the same question without any resolution.

It looks like it is designed to protect users from hackers; but it puzzles me why the initial folder is the Downloads one (it being  the most likely candidate for hackers to download hacked files !!!).

I guess users will just have to learn to navigate to other folders :(

Hola @luishp,

Estoy tratando de usar las funciones LocalFileToVar y VarToLocalFile  conjuntamente para recuperar texto de un archivo, modificarlo y volverlo a grabar el el archivo. Y solo  me funciona la primera vez. Una vez vuelvo a editar y grabar la variable en el archivo ya no recupera el contenido.

Te adjunto el archivo a ver si puedes ayudarme.

Gracias y que pases unas felices fiestas.

Roger Rey

 

 

 

Uploaded files:
  • You need to login to have access to uploads.

Hola Roger, creo que el lío estaba con el Watch más que con LocalFileToVar y VarToLocalFile.
Echa un vistazo al archivo que adjunto y si tienes cualquier duda, me dices.
Cambiando un par de cosas, he convertido tu ejemplo en un sencillo editor de textos.
Fíjate que, además de en los botones, he puesto código en la propia página.
Saludos y felices fiestas!

Uploaded files:
  • You need to login to have access to uploads.

Hola de nuevo @luishp,

Lo he probado y pasa lo mismo. La primera vez funciona,  graba el texto en el archivo. Después modifico el texto lo vuelvo a grabar en el mismo archivo y cuando lo abro no se actualiza el contenido. Lo he probado muchas veces y no hay forma. Si al abrirlo das al botón cancelar y lo vuelves abrir entonces funciona. Pero no es la solución.

Saludos,

 

Roger Rey

 

 

Hola Roger,

Creo que lo que te sucede es lo siguiente. La primera vez descargas el archivo correctamente porque no existe otro con el mismo nombre. En las sucesivas descargas el navegador detecta que ya existe un archivo con el mismo nombre y renombra el nuevo de este modo: nombre(1).txt, nombre(2).txt... para no sobre-escribir el que ya había.

Puedes configurar el navegador para que te pregunte cada vez donde deseas guardar los archivos descargados y así sobre-escribir el que ya hubiese.

Otra opción es utilizar el plugin neoPHP para guardar los archivos en el servidor.
Actualmente Chrome está desarrollando una nueva API de JavaScript que permitirá la lectura y almacenamiento de archivos locales de un modo más directo.

Saludos.

Hola de nuevo @luishp ,

Es curioso pero configurando el navegador para que me pregunte donde guardar el archivo, la primera vez al abrirlo me funciona, es decir carga el contenido en la variable, pero posteriormente si modifico el contenido y lo grabo  al  abrirlo ya no lo hace.  Es decir me pasa lo mismo que antes, solo carga el contenido de la variable la primera vez.  Tengo que inicializar la aplicación para que funcione.

Saludos,

Roger Rey

 

 

 

 

 

@rrey no consigo reproducir el problema que comentas. A mi me funciona correctamente cuando le indico que sustituya el archivo existente. Quizá puedas grabar un video mostrando lo que te sucede.
Saludos.

Mira @luishp el vídeo:  https://youtu.be/t4FxZ5PIi-w

Gracias por tu tiempo.

 

Roger, efectivamente en Chrome no funciona bien en el segundo y sucesivos intentos.
En FireFox, con el que trabajo habitualmente, funciona perfectamente.
Echaré un vistazo a ver si hay algo que se me está pasando por alto a ver si puedo solucionarlo.
Gracias a ti por tu paciencia @rrey

@rrey, ya se donde está el problema.
Fíjate que LocalFileToVar se ejecuta en el evento "change" del objeto FileInput1. Como tratamos de abrir dos veces seguidas el mismo archivo, no hay ningún cambio y por tanto el evento "change" no se ejecuta.
Si abres cualquier otro archivo de texto y después vuelves al que has editado y guardado, funcionará correctamente.
Lo curioso es que FireFox si lanza el evento "change" incluso aunque le pidas dos veces el mismo archivo.
Ahora toca descubrir como resetear el valor de FileInput1 sin intervención del usuario, lo cual creo que, por motivos de seguridad, no va a ser tarea sencilla.
Saludos.

Hola @luishp ,

Hace tiempo que te comenté el tema de LocalFileToVar para recuperar un archivo local. El problema era que si abres una vez el archivo sí funciona pero la segunda vez que vuelves abrir el mismo archivo ya no funciona. Esto ya lo comprobamos. Sabes si en VisualNeo esta acción podrá funcionar bien o hay alguna otra solución. Te lo digo porque es muy necesaria para cualquier program en el que el usuario quiera recuperar datos grabados previamente en su ordenador.

Saludos cordiales,

Roger Rey

 

 

 

Hola @rrey,

Si hay solución: poniendo el botón Input File dentro de un formulario y reseteando el formulario cada vez que cargas un archivo (así vuelve a estar en blanco y detecta el cambio de archivo al elegir el mismo). A ver si mañana saco un rato y subo un ejemplo aquí.
Saludos!

@rrey aquí tienes la solución (adjunto). Como te comentaba, el truco está en resetear el File Input y para eso hay que ponerlo dentro de un formulario. Si tienes alguna duda, me dices.
Saludos!

Uploaded files:
  • You need to login to have access to uploads.

Muchas gracias @luishp,

Funciona perfecto.

Saludos cordiales,

Roger Rey