#1 Re: mORMot 1 » post multipart data » 2015-04-17 12:35:26

Thanks but I don't understand how this relates to the TWinHttp.Post request that I'd like to send:

  SetLength(MultiPart, 1);
  MultiPart[0].Name := 'file';
  MultiPart[0].FileName := ExtractFileName(Filename);
  MultiPart[0].ContentType := 'application/octet-stream';
  MultiPart[0].Encoding := 'UTF8';
  MultiPart[0].Content := Body;

  ctx := TSQLRestServerURIContext.Create;
  ctx.InputAsMultiPart(MultiPart);

  // what to do to send with TWinHttp.Post ?

#2 mORMot 1 » post multipart data » 2015-04-17 08:55:51

remko
Replies: 3

I need to send a zip file to a rest service as http(s) post with content-type multipart/form-data. The rest service will return json data to indicate success/failure.

I found this forum post: http://synopse.info/forum/viewtopic.php?id=2366 but is there any documentation on how to use it or perhaps a small example?

#3 Re: mORMot 1 » DocVariantType.Data(1<>TDocVariant) Exception » 2015-04-17 08:38:34

Silly mistake on my side, just started exploring and took this from example. Thanks for the clear explanation.

#4 mORMot 1 » DocVariantType.Data(1<>TDocVariant) Exception » 2015-04-17 06:52:44

remko
Replies: 2

I'm calling a REST service with mORMot like this:

function TForm9.Logon(const IPAddress: String; const Username, Password: String): Boolean;
var
  t: variant;
  json: RawUTF8;
  url: String;
  Values: TPUtf8CharDynArray;
  jsondata: TDocVariantData;
begin
  Result := False;

  url := Format('https://%s/user/login', [IPAddress]);

  TDocVariant.New(t);
  t.username := Username;
  t.password := Password;
  json := TWinHTTP.Put(url, t, 'Content-Type: application/json', True);
  jsondata := DocVariantData(_json(json).jsondata)^;
end;

This is the returned data:

{"serverinfo":{"authtype":"local","api_key":"b61c7ef7-2f44-41d3-bb3e-69681fe999b6","metricsip":"192.168.1.23","port":"8443","metricsport":"8081","ip":"192.168.1.23","version":"1.1.0.19"}}

DocVariantData fails with Exception class EDocVariant with message 'DocVariantType.Data(1<>TDocVariant)'.

function DocVariantData(const DocVariant: variant): PDocVariantData;
begin
  with TVarData(DocVariant) do
    if VType=DocVariantType.VarType then
      result := @DocVariant else
    if VType=varByRef or varVariant then
      result := DocVariantData(PVariant(VPointer)^) else
    raise EDocVariant.CreateUTF8('DocVariantType.Data(%<>TDocVariant)',[VType]);
end;

DocVariantData is null but why? Is there something invalid/unexpected in the returned JSON?

Board footer

Powered by FluxBB