#1 2017-11-02 11:44:46

jaclas
Member
Registered: 2014-09-12
Posts: 215

Send binary data in interface-based service - without encoding!

Please add the ability to send binary data in raw mode (without base64 encoding) in interface-based services. Maybe some dedicated type like TBinaryBlob or TRAWData?

This would be very useful in some cases!

Offline

#2 2017-11-02 16:46:31

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

Re: Send binary data in interface-based service - without encoding!

I agree, very useful.

Offline

#3 2017-11-03 03:27:04

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: Send binary data in interface-based service - without encoding!

I agree.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#4 2017-11-03 11:34:19

Stregor
Member
Registered: 2016-05-05
Posts: 2

Re: Send binary data in interface-based service - without encoding!

Will be very useful, i agree.

Offline

#5 2017-11-03 16:18:47

eraldo
Member
From: Brasil
Registered: 2010-07-22
Posts: 69
Website

Re: Send binary data in interface-based service - without encoding!

Me too!

Offline

#6 2017-11-04 20:03:41

JD
Member
Registered: 2015-08-20
Posts: 118

Re: Send binary data in interface-based service - without encoding!

I fully agree and I would love to see this functionality

Offline

#7 2017-11-04 21:14:33

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Send binary data in interface-based service - without encoding!

Okay, okay, I will add it!
wink

Offline

#8 2017-11-04 21:42:06

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Send binary data in interface-based service - without encoding!

Hurrah! :-)


Thx!

Offline

#9 2017-11-05 12:23:25

JD
Member
Registered: 2015-08-20
Posts: 118

Re: Send binary data in interface-based service - without encoding!

ab wrote:

Okay, okay, I will add it!
wink

Thanks a lot!

Offline

#10 2017-11-06 16:34:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Send binary data in interface-based service - without encoding!

If your purpose is to upload some binary data, RawByteString and TSQLRawBlob input parameters will by default be transmitted as Base64 encoded JSON text.

You may define Client-Server services via methods to transmit raw binary, without the Base64 encoding overhead. It would allow low-access to the input content type and encoding, even with multi-part file upload from HTTP.

As an alternative, if you use default TSQLRestRoutingREST routing, and defined a single RawByteString or TSQLRawBlob input parameter, it will be processed as a raw POST with binary body defined with mime-type 'application/octet-stream'. This may be more optimized for remote access over the Internet.
See https://synopse.info/fossil/info/4cfc722c69

Offline

#11 2017-11-14 11:14:02

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Send binary data in interface-based service - without encoding!

Does this mean that the method can have only one parameter? Eg.

procedure SendBlob (const aBlob: RawByteString);

And if I write the method:

Procedure SendBlob(aBlobKind: Integer; const aBlob: RawByteString);

then aBlob will be encoded with Base64?

Offline

#12 2017-11-14 11:49:43

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: Send binary data in interface-based service - without encoding!

Yes. Current implementation use JSON as a transport for multiple parameters. There is no possibility to serialize a binary data to JSON without base64 encoding.

Offline

#13 2017-11-14 13:49:29

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Send binary data in interface-based service - without encoding!

With one parameter this is not very useful :-( There is no way to tell what is in the blob, probably need to use http header for additional info.

It would be useful to tag/register a method so that its parameters are not serialized.
Maybe worth consider to expand TServiceFactoryServer interface by adding method:

 function DoNotEncodeParams(const aMethod: array of RawUTF8): TServiceFactoryServer;

Is it possible to realize?

Offline

#14 2017-11-14 18:32:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Send binary data in interface-based service - without encoding!

Use manual serialization to a single RawByteString in such case.

There are such serialization available in the framework.

Offline

#15 2018-02-12 12:30:55

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Send binary data in interface-based service - without encoding!

I found problem on this topic.
I get exception:

TSQLRestRoutingREST.Error: 
{"errorCode":406,  "errorText":"sicShared execution failed (probably due to bad input parameters) for TMyService.SendFilePart"}

See for reason:

EenCksJv.png

Offline

#16 2018-02-12 12:58:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Send binary data in interface-based service - without encoding!

How is your service defined?

One input parameter without JSON encoding is NOT supported yet, as documented and stated above in this forum thread.

Use a method-based service instead to upload some binary content from the client.

Offline

#17 2018-02-12 13:13:05

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Send binary data in interface-based service - without encoding!

Not supported?

Then why you wrote above:

"As an alternative, if you use default TSQLRestRoutingREST routing, and defined a single RawByteString or TSQLRawBlob input parameter, it will be processed as a raw POST with binary body defined with mime-type 'application/octet-stream'. This may be more optimized for remote access over the Internet.
See https://synopse.info/fossil/info/4cfc722c69"
?

And what changes has this commit? https://synopse.info/fossil/info/4cfc722c69


btw on other (text) files this way acts properly (send without json and base64 encoding)

Last edited by jaclas (2018-02-12 13:15:38)

Offline

#18 2018-02-12 14:18:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Send binary data in interface-based service - without encoding!

I forgot about this commit. wink
This is event documented in https://synopse.info/files/html/Synopse … l#TITL_197

Are you sure you use the proper mime type, with raw binary content (no base64 encoding)?
Try to find out using the debugger why TSQLRestRoutingREST.ExecuteSOAByInterface doesn't understand your client query.

Offline

#19 2018-02-12 14:28:15

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Send binary data in interface-based service - without encoding!

For send PDF file header is:

POST /server/SomeService.SendFilePart HTTP/1.1
Accept: */*
FILEID: 84317faa3d2516d189da1e356e12e4fe5f55eeea8970a09d26739ec690e0c4fb
Content-Type: application/pdf
User-Agent: Mozilla/5.0 (Windows; mORMot 1.18 TWinINet)
Host: localhost:8090
Connection: Keep-Alive
Accept-Encoding: gzip, deflate
Content-Length: 1048576

%PDF-1.4
%ŕáâă
2 0 obj
<</Filter /FlateDecode
/Length 11656951
>>
stream
xśĚÝÁŽćHš¬ç}_ĹÜŔNŇé$·
[...]­

for XML:

POST /server/SomeService.SendFilePart HTTP/1.1
Accept: */*
FILEID: 8472f3d762a2f42ebde6a9bf9fba0806d9c8e59221fc0dafd3fe05dd1a94050c
Content-Type: application/octet-stream
User-Agent: Mozilla/5.0 (Windows; mORMot 1.18 TWinINet)
Host: localhost:8090
Connection: Keep-Alive
Accept-Encoding: gzip, deflate
Content-Length: 1048576

<?xml version="1.0" encoding="UTF-8"?>
<Migration>
<Session Type="Online">
	<Platform Type="Source">
[...]

Content-Type is different for PDF and for XML, how to force properly value of Content-Type?

Offline

#20 2018-02-12 20:20:19

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Send binary data in interface-based service - without encoding!

It should be exactly application/octet-stream - as documented.

Offline

#21 2018-02-12 21:06:33

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Send binary data in interface-based service - without encoding!

But how to set it? For now I don't set the Content-Type header.

Offline

#22 2018-02-13 09:31:01

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Send binary data in interface-based service - without encoding!

F3oDCU6q.png

is not exactly like you wrote:

"if you use default TSQLRestRoutingREST routing, and defined a single RawByteString or TSQLRawBlob input parameter, it will be processed as a raw POST with binary body defined with mime-type 'application/octet-stream'"

Can you correct it?

Offline

#23 2018-02-13 12:24:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Send binary data in interface-based service - without encoding!

Yes, you are right, this is an issue.
Even if setting 'application/pdf' is the right way on the client side.

I guess that the server side is to be fixed.
Please try https://synopse.info/fossil/info/26d3008868

Offline

#24 2018-02-13 13:02:50

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Send binary data in interface-based service - without encoding!

Now is ok (probably ;-)
Thx Arnaud

Offline

#25 2018-02-13 16:37:33

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

Re: Send binary data in interface-based service - without encoding!

@jaclas what font do you use in the IDE?

Offline

#26 2018-02-13 16:53:16

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Send binary data in interface-based service - without encoding!

@Junior/RO

Source Code Pro Semibold

Offline

Board footer

Powered by FluxBB