[fpc-pascal] Prorammatically sending file using HTTP POST?
R0b0t1
r030t1 at gmail.com
Thu May 3 16:33:25 CEST 2018
On Wed, Apr 4, 2018 at 6:50 AM, Bo Berglund <bo.berglund at gmail.com> wrote:
> I have written a Lazarus/FPC program to configure an IoT device via a
> tcp server I have implemented on the device. It all works well for
> setting the parameters etc.
> Now I want to also add a firmware update function to this configurator
> program, but I could use some advice regarding the way to send the
> file data...
>
> The firmware updater service is running on the IoT device on port 80
> as a web server and when one connects to that URL with a browser the
> following happens:
>
> 1) A login dialog is shown where a username and a password needs to be
> entered.
>
> 2) Next a very simple web form is shown with the following source:
> <html>
> <body>
> <form method='POST' action='' enctype='multipart/form-data'>
> <input type='file' name='update'>
> <input type='submit' value='Update'>
> </form>
> </body>
> </html>
>
> 3) When the "Browse..." button is clicked one gets to navigate the
> file system and select a file to upload. The name is then displayed in
> a box.
>
> 4) Upon hitting the submit button "Update" the file is sent to the IoT
> device and used to update the firmware.
>
> Now I want to get rid of the web browser step and integrate the
> functionality of the form into the configuration program, but I don't
> know how to actually send the POST data to the IoT device so it will
> work...
>
> The instructions for the WebUpdater service I have added to the IoT
> device has a second alternative for uploading the firmware using curl:
>
> curl -u user:pwd -F "image=@firmware.bin" <ip-address>:80/firmware
>
I'd strongly recommend using SSH/SCP instead, or at least HTTPS.
Certificates for HTTPS can be more difficult to set up on nontechnical
user's computers.
Cheers,
R0b0t1
> I don't want to require that curl is present on the PC where my
> program will run, though, so I want to implement the actual post
> message in my fpc code.
>
> Does someone have a suggestion on how to do this?
>
> By the way, I am using the Indy10 components via the indylaz package.
> Lazarus is 1.8.0 and FPC 3.0.4 on Windows7.
>
More information about the fpc-pascal
mailing list