KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Web Server Link to Download Picture File or PDF
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: March 29, 2021

Most browsers have the ability to display an image or PDF directly in the browser itself. When a browser detects that the link references one of these files it will typically display the image.

For example the following code will typically display the image in the browser:

$pathToPic_Text:="C:\\Users\\UserName\\Pictures\\MyPic.png"
WEB SEND FILE($pathToPic_Text)

To make respond to the web request and allow the picutre to be downloaded
Below is an example code snippet of how to respond to a web request with a downloadable picture file or PDF on the 4D Web Server.
ARRAY TEXT($headerArrText;0)
ARRAY TEXT($valueArrText;0)

APPEND TO ARRAY($headerArrText; "Content-Disposition")
APPEND TO ARRAY($valueArrText; "attachment; filename=\"filename.jpg\"")

WEB SET HTTP HEADER($headerArrText; $valueArrText)

$pathToPic_Text:="C:\\Users\\UserName\\Pictures\\MyPic.png"

WEB SEND FILE($pathToPic_Text)

By specifying the the link is an attachment with the header, the browser will download the file instead.