Page 1 of 1

Download file via html5

Posted: Mon Dec 14, 2015 6:20 pm
by Marco Turco
Hi all,
I have a FWH app running into a W7 virtual machine.
I would like to add a button to download a file via html from a remote server.

Is there a function to do this ? Thank you in advance.

Re: Download file via html5

Posted: Mon Dec 14, 2015 6:34 pm
by Enrico Maria Giordano
Marco,

this is what I'm using (but it has nothing to do with HTML5):

Code: Select all | Expand

FUNCTION GETURLTOFILE( cUrl, cFile, lAuth )

    LOCAL lOk := .F.

    LOCAL oCli

    DEFAULT lAuth := .F.

    TRY
        oCli = TIPClientHttp():New( cUrl )

        IF lAuth THEN oCli:UseBasicAuth()

        IF EMPTY( oCli ); BREAK; ENDIF

        oCli:nConnTimeout = -1

        IF !oCli:Open(); BREAK; ENDIF

        DEFAULT cFile := oCli:oUrl:cFile

        IF !oCli:ReadToFile( cFile ); BREAK; ENDIF

        lOk = !EMPTY( oCli:cReply ) .AND. "OK" $ UPPER( oCli:cReply )

        IF !lOk; FERASE( cFile ); ENDIF
    CATCH
    END

    IF !EMPTY( oCli ); oCli:Close(); ENDIF

    RETURN lOk


EMG

Re: Download file via html5

Posted: Mon Dec 14, 2015 9:39 pm
by Marco Turco
Hi Enrico,
not bad, thank you, anyway, the best for my customer would to "browse" the directory and select the file instead to write the full url.
Any ideas about this ?

Re: Download file via html5

Posted: Mon Dec 14, 2015 10:05 pm
by Enrico Maria Giordano
Marco,

do you mean "browse the remote directories" or the local ones?

EMG

Re: Download file via html5

Posted: Mon Dec 14, 2015 10:59 pm
by Marco Turco
I mean a remote public directory.
A customer has a mac server with static ip and I would like to provide the feature to select a file there from my FWH app (hosted on another server)

Re: Download file via html5

Posted: Mon Dec 14, 2015 11:07 pm
by Enrico Maria Giordano
Marco,

I don't know, sorry. :-(

EMG

Re: Download file via html5

Posted: Tue Dec 15, 2015 4:14 am
by anserkk
Marco Turco wrote:I mean a remote public directory.
A customer has a mac server with static ip and I would like to provide the feature to select a file there from my FWH app (hosted on another server)


Code: Select all | Expand

oInternet := tInternet():New()
oFtp      := tFtp():New(cIp,oInternet,cFtpUserName,cFtpPassword)
aFiles:=oFtp:Directory(cFolderName+"\"*.* )


Display the contents of the aFile to the user to choose the required file and then download it. Just an idea

Regards
Anser

Re: Download file via html5

Posted: Tue Dec 15, 2015 8:49 am
by Enrico Maria Giordano
Anser,

I don't think Marco wants to use FTP. Marco?

EMG

Re: Download file via html5

Posted: Tue Dec 15, 2015 9:36 am
by Carlos Mora
Hi Marco
Marco Turco wrote:I would like to add a button to download a file via html from a remote server.


Enrico's code is fine for downloading, you should to provide the link to the file. If you need to surf the website to find the file, there are 2 options: is the webserver using WEBDAV, or just HTTP?
WEBDAV is like ftp built on top of http, would make things easy. If it's published as an html website, it will depend on how the website publishes content so a procedure can be made to browse it.

What software is running in the server? Just a webserver like Apache? Or sth else?

Re: Download file via h tml5

Posted: Tue Dec 15, 2015 11:49 am
by Marco Turco
I would avoid to use the ftp.
The EMG solution is fine but I would prefer a solution like that you have (for example) on a webmail where to attach a file you press a button and you can select it from your local computer.