How do i download a download a file from app servicer?


Guest

Im trying to get a file downloaded from app server to the app application directory such as

from server: http://www.mydomain.com/group.html

to this location

/www/app/files/group.html

what is the best control to use and how?

Thanks in advance.


DecSoft

Hello Kasito,

I am not sure if you can download a file in that place, since they are part of the application's resources. However, if you can do it, you must use (at least until this plugin are not implemented out of the box) the FileTransfer and the Files Cordova's plugins, as I explain you in this other post. Look at the possible app's directories we can use to store the downloaded files.

P.S. Why you need to download such file? You can't simply put their URL in an IFrame control in order to show it?



Guest

But David. is there anywhere a file can be download to in the app? i just want a file to be download to a location on the app then i can do something with it.

i also want to know if i can check if the file does exist.

Is all this possible?

and how do i do it.


DecSoft

Hello.

But David. is there anywhere a file can be download to in the app? i just want a file to be download to a location on the app then i can do something with it.

i also want to know if i can check if the file does exist.

Is all this possible?

and how do i do it.

Of course it's possible! In this other post I place all the appropiate links in order to start.



Guest

Hi David, i think at my level of using AB, i will hold the implementation of downloading a file, cos its really though for me.

But can i check if a file exist on the app server? what technic i can use to check that? i know some http control can do it but how?

What i want is AB to check if file exist, then reply with True or False - so that i can use that to decide an action. i want this check to be performed for each installation.

Thanks.


DecSoft

Hello Kasito,

We can check an online resource or file using the HttpClient control. This control has two events: Success and Error. The Error event is reaised, for example, if a resource or file can't be located. However, this also may depend a bit on our app's server.

For example, if we try to get a resource like "http://www.nonexisting.com/myfile.html", the HttpClient's Error event is fired, but the HTTP status code variable is "-1", that can appear a bit confusing if we expect a 404 error code in that variable.

An HTTP "-1" status code means the HTTP request can't be completed. We must remember here our HTTP requests requires the Cross-origin resource sharing (CORS) enable in the server side, and then our above requests fail in the first stage and can't be completed.

So our problem to determine if a resource or file really exists probably can be handle better if certain script in our server do the job (examining if the requested file exists) and offer to us the appropiate HTTP status code: a 404 status code, for example.

In conclusion we can use an HttpClient control with an URL like: "http://www.our-app-server.com/checkFiles.php" passing the name of the file as a param in a GET HTTP request. The "checkFiles.php" then do their job and prepare the appropiate response.

If after execute the GET HTTP request the "Success" event is fired, then we can understand the resource or file we looking for really exists. If after execute the request the "Error" event is fired, we can examine the error code, but, anyway, the file do not exists.

Maybe this all appear a bit complicated... but in fact all of them can be resumed in this: we can made an GET HTTP request in order to determine if a resource or file exists or not.



Guest

Ok David, Thanks.

I think what i have to do is execute the get HTTP request and if response == success then file exist else i will consider nothing exist. Listening to the success response can solve my solution i think.

maybe this will be less complicated for me.


DecSoft

Hello Kasito,

Certainly, in general terms, a Success event means the resource or file exists. The "problem" can be in the Error event, that is, we must determine if the HTTP request has been completed or if we have the expected (for example a 404) error code. You can try it and post here if you have any further question.


Todo el mundo puede leer el foro de soporte de DecSoft para aprender del mismo, sin embargo, sólo los clientes de DecSoft pueden abrir nuevos hilos. Compre una o más licencias de productos de DecSoft y obtendrá este y otros beneficios.

Este sitio utiliza "cookies" útiles para almacenar sus preferencias.

Bien. Ocultar esta nota. Obtener más información.