Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Examples of downloading and uploading files.
Sat, Aug 31 2024 6:49 AMPermanent Link

Graeme Keast

Hi

I have been looking for examples of EWB code that

1   Downloads a file from the server to the client's hard drive, preferably without any user intervention.
2   Uploads a file from the Client to the server.

For both cases I am after samples of the client as well as the server code. If possible could the server code be written as a Delphi dll as my server consists of only Delphi dlls.

Would you please assist.

Regards
Sat, Aug 31 2024 10:05 AMPermanent Link

erickengelke

Avatar

Graeme Keast wrote:
>I have been looking for examples of EWB code that

> 1   Downloads a file from the server to the client's hard drive, preferably without any user intervention.

Just set window.location.href = 'https://url.....'

and have your server return a file rather than content, setting the filename and the file content Mime type.

If your server returns a file with filename, the web page will not change but the file will be downloaded.  Otherwise, the web page will now be that content.

>2   Uploads a file from the Client to the server.

There are two ways to do that:

1. Use TFileComboBox - which you put into a THTMLForm and set its URL - that's the standard way.  It's the easiest solution.

OR

2. Buy my Nice component library, and then you can save anyghing from your browse to a file.  So if you were to download the 'file' saved in a field of your datastructure, you can write it directly to disk from your browser.


> For both cases I am after samples of the client as well as the server code. If possible could the server code be written as a Delphi dll as my server consists of only Delphi dlls.

I've done several servers in Delphi, but the actual code depends on what server/middleware your are using: Apache, Mormot, IIS, etc.

My answers are a little vague, but I hope I've given you the seeds to get started.
EWB Programming Books and Nice Component Library
See my EWB BLOG posts, at:
http://www.erickengelke.com
Fri, Sep 6 2024 10:05 PMPermanent Link

Graeme Keast

Hi Erik

Thanks for your reply; apologies for my tardy response.

I do have your Nice components and will have a look at them.

Not being a web developer I have found the transferring of files to and from the server a little hard to understand at times.

The features I am after are:

1   scan the users's machine for files to upload
2   upload these files to the server (I believe you Nice components do points 1 and 2 - I am yet to check this out)
3   Download a file (or many files) to the user's machine to a known location and with a specified name without any user intervention
4   Show the contents of one of these files (if possible) back to the user (your Nice components may assist here)
5   Download and show the contents of a file (if possible) without copying the file to disk.

Regards
Graeme
Fri, Sep 6 2024 10:48 PMPermanent Link

erickengelke

Avatar

Graeme Keast wrote:
>Not being a web developer I have found the transferring of files to and from the server a little hard to understand at times.

>The features I am after are:

> 1   scan the users's machine for files to upload

I think this isn't possible without writing browser extensions.  This is a security feature of web browsers to prevent malicious sites from stealing data from your computer.  You must volunteer the filename.

> 2   upload these files to the server (I believe you Nice components do points 1 and 2 - I am yet to check this out)

I covered this in:
https://www.erickengelke.com/posts/post36.html

And how much memory is available to hold the files:
https://www.erickengelke.com/posts/post37.html


> 3   Download a file (or many files) to the user's machine to a known location and with a specified name without any user intervention

https://www.erickengelke.com/posts/post36.html  shows how.

> 4   Show the contents of one of these files (if possible) back to the user (your Nice components may assist here)

https://www.erickengelke.com/posts/post36.html. shows how to display PNG, JPG and PDF files.

However Word and Excel and many other files don't work that way because the browser cannot interpret them - they are not Internet standards.

>5   Download and show the contents of a file (if possible) without copying the file to disk.

Uusally you can just open a TBrowser and set its URL property to the file name.  Note, your web server will have to say the file's MIME type.   How you do that depends on your server programming langauge.

Good luck.

Erick
EWB Programming Books and Nice Component Library
See my EWB BLOG posts, at:
http://www.erickengelke.com
Fri, Sep 6 2024 10:48 PMPermanent Link

erickengelke

Avatar

Graeme Keast wrote:
>Not being a web developer I have found the transferring of files to and from the server a little hard to understand at times.

>The features I am after are:

> 1   scan the users's machine for files to upload

I think this isn't possible without writing browser extensions.  This is a security feature of web browsers to prevent malicious sites from stealing data from your computer.  You must volunteer the filename.

> 2   upload these files to the server (I believe you Nice components do points 1 and 2 - I am yet to check this out)

I covered this in:
https://www.erickengelke.com/posts/post36.html

And how much memory is available to hold the files:
https://www.erickengelke.com/posts/post37.html


> 3   Download a file (or many files) to the user's machine to a known location and with a specified name without any user intervention

https://www.erickengelke.com/posts/post36.html  shows how.

> 4   Show the contents of one of these files (if possible) back to the user (your Nice components may assist here)

https://www.erickengelke.com/posts/post36.html. shows how to display PNG, JPG and PDF files.

However Word and Excel and many other files don't work that way because the browser cannot interpret them - they are not Internet standards.

>5   Download and show the contents of a file (if possible) without copying the file to disk.

Uusally you can just open a TBrowser and set its URL property to the file name.  Note, your web server will have to say the file's MIME type.   How you do that depends on your server programming langauge.

Good luck.

Erick
EWB Programming Books and Nice Component Library
See my EWB BLOG posts, at:
http://www.erickengelke.com
Image