Upload an image using a service


how can I upload an image with an xdata service?
I'd like to have something like this interface

[httpPOST]function UploadImage(Image: sometype): TJsonObject;

where sometype is a type I do not know.

For "normal" post-functions I use something like

[httppost]function DoSomething(param: Integer): TJsonObject;
[httppost]function DoSomething(param: TSomeType): TJsonObject;

and transfer the object as JSON Object. But what type can I use for a file upload from a web form via POST?
  1. <form action="https://myserver/UploadImage" method="post" enctype="multipart/form-data">
  2. <input type="file" name="fileToUpload" id="Image">
  3. <input type="submit" value="Upload Image" name="submit">
  4. </form>
Do You have any advice? What enctype do I use and how can I get the data in my service function?

Kind regards

You could use TArray<byte> as the sometype. But that would be a "Rest" way to communicate with it, via TXDataClient, or posting a JSON with base64 encoding.

If you want to use raw HTTP using web form, please refer to "FileUpload" demo in Sparkle demos.
Hello Wagner,
thanks for Your answer. Great support as always :-)
You asked the right question. It's good to know a way with raw data and functions, but maybe for my situation really using REST with Base64 and JSON is the better solution.