I am working on a web application in Lazarus. It is a command line program, which will be used in the web interface as the cgi-bin handler for configuring a data collection system running on Raspberry Pi.
The app will output html pages formatted such that Apache can handle the serving of them to the caller. This works great so far.
It also reads the posted data when the user submits a request and adjusts the returned webpage accordingly.
I have this working fine now for regular form-oriented stuff like sending in config data and extracting them from the call and acting on them.
But now I have come to a showstopper when I want the user to select a definition file on his PC to send it into the system.
I use an input control of type "file" like so:
<form method=POST action="/cgi-bin/mywebhandler" enctype="multipart/form-data">
Select file:
<input type="file" name="myFile"><br><br>
<input type="submit">
</form>
Then in the handler "mywebhandler" I receive in the post data the item
myFile=selectedfilename
I can extract the name this way, but how can I access the file
content?
Is it supplied in the posted data, and if so in what format?
How should I read the data in my application?
What I do for post data is that I read each item in a loop with readln() until it returns an empty string. This is what I am required to do according to the specs I have read and it does work...
Every read should produce a name=value pair where data are web encoded such that spaces become + and other characters are hex encoded and sent for example as %3B for the character ; etc.
But what happens with the
contents of the file selected as shown above?
EDIT:I modified the form tag in my example above according to PascalDragon's suggestion.