#1 2015-07-28 12:15:58

cypriotcalm
Member
Registered: 2015-02-18
Posts: 122

How transfer a TSQLRawBlob field as JSON

I tried to find this option in the documentation, but I failed :-(

I have a class:

  TMyJSONData = class(TSynPersistent)
  ...
  published
    property Data: TSQLRawBlob read fData write SetData;
  end;

I pass some data to the service, on the client side everything is okay, but on the server side I don't get the binary data transmitted.

  //CLIENT SIDE        
  aJPEG.LoadFromFile('C:\Users\Public\Pictures\Sample Pictures\Desert.jpg');
  aMyJSONData.Data := StreamToRawByteString(aJPEG); 

  ....
  DataImportService.Save(aMyJSONData);


  // SERVER SIDE
  aDevice.Data -> the property is empty

How do I enable the transfering of the TSQLRawBlob fields?!

The only one thing what I found in the documentation was:
"- by default, TSQLRawBlob properties are serialized as null, unless woSQLRawBlobAsBase64 is defined"

But it was not explained how and where I can do this!

Thx for your help!

Offline

#2 2015-07-28 15:15:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,048
Website

Re: How transfer a TSQLRawBlob field as JSON

Try with RawByteString type.

Offline

#3 2015-07-28 18:55:43

cypriotcalm
Member
Registered: 2015-02-18
Posts: 122

Re: How transfer a TSQLRawBlob field as JSON

ab wrote:

Try with RawByteString type.

I've tried it, the value is still empty. I used the debugger and discovered this code in the unit SynCommons:

function Base64ToBinLength(sp: PAnsiChar; len: PtrInt): PtrInt;
var Table: ^TConvertBase64ToBinTable absolute ConvertBase64ToBin;
begin
  if (len=0) or (len and 3<>0) then begin <--- COULD BE THIS CHECK AN ISSUE??
    result := 0;
    exit;
  end;
  if ConvertBase64ToBin=nil then
    InitConvertBase64ToBin;
  if Table[sp[len-2]]>=0 then
    if Table[sp[len-1]]>=0 then
      result := 0 else
      result := 1 else
      result := 2;
  result := (len shr 2)*3-result;
end;

Offline

#4 2015-07-28 19:21:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,048
Website

Re: How transfer a TSQLRawBlob field as JSON

AFAIK, in Base64 encoding, the incoming length should always be a multiple of 4 bytes, by design.

Offline

#5 2015-07-28 20:37:54

cypriotcalm
Member
Registered: 2015-02-18
Posts: 122

Re: How transfer a TSQLRawBlob field as JSON

ab wrote:

AFAIK, in Base64 encoding, the incoming length should always be a multiple of 4 bytes, by design.

To be honestly, I don't know, but the value is still emtpy :-(

Offline

Board footer

Powered by FluxBB