Jump to content
Yaron

Image from Form has no value

Recommended Posts

I am trying to upload an image from an html form (see below) to a MARS server.

Previously, I was able to get this working when the client was written in Delphi, but now the client is a standard browser and the code fails (LParam.isFile returns false).

 

HTML form:

<form method="post">
<input type="text" name="ImageName" required><br>
<input type="file" accept="image/jpeg" name="ImageFile" required>
</form>

 

The code I used to get the image that doesn't seem to work in this case :

var
  lParam  : TFormParam;
  mStream : TMemoryStream;
begin
    For lParam in aParams do
    Begin
      If (SameText(lParam.FieldName, 'ImageFile')) then
      Begin
        If (LParam.isFile) then
        Begin
          mStream := TMemoryStream.Create;
          mStream.Write(lParam.AsFile.Bytes,Length(lParam.AsFile.Bytes));
          mStream.Position := 0;

          Try
            mStream.SaveToFile('d:\test.jpg');
          Finally
            mStream.Free;
          End;
      End;
    End;
end;

Any ideas?

Share this post


Link to post
Posted (edited)

I believe that I solved this issue, I was missing enctype="multipart/form-data" in the form's statement.

Edited by Yaron

Share this post


Link to post

Hi, yes the HTML form should be a multipart/form-data one...

Glad you solved 😉

 

Sincerely,

Andrea

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×