You are not logged in.
Hi,
I'm trying to upload Images from a client to a service vice versa.
I'm using the MVC so there's an interface defined which is shared by the service and the client.
I tried to send a image from the client like this (for testing purpose):
varvar
LPicture : TSynPicture;
LIntf : IAccount;
LRawBlob : TSQLRawBlob;
LRawBytes : RawByteString;
begin
...
try
LPicture := TSynPicture.Create;
LPicture.LoadFromFile(OpenDialog1.FileName);
if LPicture.Empty then
begin
Exit;
end;
SaveAsRawByteString(LPicture, LRawBytes, gptPNG, 80, 300);
LRawBlob := BlobToTSQLRawBlob(LRawBytes);
if FClient.Services['Account'].Get(LIntf) then
begin
LIntf.UploadPicture(1, LRawBlob, 1);
end;
finally
FreeAndNil(LPicture);
end;
I do receive the LRawBlob field at my service but the bytstream is corrupte I think I need to encode the stream as Base64.
So here's my question:
If I have to manually encode the LRawBytes as Base64 wouldn't it be much easier to use RawUTF8 instead of TSQLRawBlob or do I miss something and there's some magic I could use?
P.S.: @ab: Greetings from the EKON22 I'm still missing your EKON example code.
Last edited by deitysou (2018-11-10 18:19:24)
Offline
How is your IAccount defined?
To upload efficiently some binary, better define a single RawByteString parameter (without the 1, ..., 1 other values), so that JSON marshalling will be by-passed and no Base64 encoding will be made.
See https://synopse.info/files/html/Synopse … l#TITL_197
Offline
Thank you.
My Interface is defined as:
IAccount = interface(IInvokable)
...
function UploadPicture(const sortid: Integer; picture: TSQLRawBlob): Boolean;
end;
So the new code is implemented like this:
function TDfXAccount.UploadPicture(const sortid: Integer; picture:
TSQLRawBlob): Boolean;
At least I need one id (sortid) for this function call. Is there a way to keep this parameter?
Offline
Thank you I'll try that.
And thank you for uploading the EKON example.
Offline
I tried your advice and it worked well until I set the OnlyJSONRequests option true.
I need to have all clients to send JSON only so how could I realize that?
Also I noticed that my Delphiclient (which is using the interfaces) sends request like "Account.Login" instead of "Account/Login".
Can I disable this behavior?
Also I tried to use the JWTForUnauthenticatedRequest but I didn't figure out how to omit auth check for some functions like Account/Register and Account/Login
where no JWT is available.
Sorry for bothering you.
Last edited by deitysou (2018-11-13 12:09:18)
Offline
I understand your requirement the other way round, sorry.
I thought it was about avoiding JSON/Base64 conversion.
So if you use RawByteString with other parameters (as you did first) it will make an hidden Base64 encoding/decoding as you expect.
Offline