Question:
Good afternoon.
A customer wants to send me an .xml file
I created a DataSnap Rest Application project.
I implemented the method as follows for JSON
function TFo_SM_Fornecedor.updateFornecedor(TObjJson: TJsonObject): TJsonValue;
Var
Fornecedor: TFornecedor;
begin
Fornecedor := TJson.JsonToObject<TFornecedor>(TObjJson.toJson);
Try
Result := TJSONString.Create('Incluindo Cliente..: ' +
Fornecedor.tx_razaosocial);
Finally
FreeandNil(Fornecedor);
End;
end;
To receive a TJsonObject type works perfectly.
But as I said at the beginning I will receive an .xml.
I've done several codes in delphi to receive an xml and put the values in the base, but it's the first time I have to develop a server and I don't have a direction.
Can any of the colleagues give me a light? At first (a few days ago) I'm trying to change the line parameter
function TFo_SM_Supplier.updateSupplier(TObjJson: TJsonObject):
for something like
function TFo_SM_Supplier.updateSupplier(pFile_XML: TStringTream):
But I'm unsuccessful. If any of you can provide me with a light, I would appreciate it.
Answer:
I don't think I need to change the parameter, you could receive the xml as a String without problems, it would just be enough to identify a specific field in json…
I think of something sent to you like:
[
{
"xml": "todo xml aqui"
}
]
Your function would receive a simple json and test if the key is "xml" treat it as xml, if not keep doing what you already do…
This I have implemented and it works perfectly for various file formats and my API.
To send me an image I request it to be a String, or a base64, to send me an MP3 send me a String, the requester converts it into TStringTream
and sends me the bytes into String.
On my side I just recognize the key.