I built a DataSnap REST server using Delphi XE2, and I added a server method for uploading files via TStream:
function TServerMethods.updateUploadFile(sFilename: string; UploadStream: TStream): string;
I want to be able to call this from several different clients (Android, iOS, etc.), and I tested this method with various REST clients such as Postman (Chrome plugin). However, so far I cannot get it to accept content for the HTTP POST body. Whenever I send a POST command, I always get the following response:
{"error":"Message content is not a valid JSON value."}
I tried using different Content-Type settings, but nothing works. Looks like DataSnap is insisting that the content is JSON? I tried pasting some valid JSON into the content area, but this also gave the same answer.
Has anyone successfully used TStream as an input parameter to a DataSnap server method? Should I do it differently? I used TStream as an output parameter to download files many times and it works well, this is my first attempt to download.
UPDATE
I made a quick Delphi DataSnap client to test the uploadFile server method, and all this works fine. Then I used Fiddler to check the POST command that the Delphi client uses to send the TStream in the content body, and noticed that this is a JSON array of integers (bytes), for example. [37,80,68,70,45,49,46,51,13,10] . So I can see that I can change my Android / iOS clients to convert binary data to this byte array format before POSTING, but this is an overhead that I could get around. If the DataSnap passes the source binary when the TStream is a return parameter, why can't it pass the source binary as an input parameter?