Download file using service xdata and webcore save how binary file

Well. I got around that by just encoding the file (binary > Base64) in the XData service, and then decoding it in the client (Base64 > binary) so no need to worry about any kind of Bytes or TJSUnit8Array issues. However, if what you're working with is a binary TStream, then let's figure out what is needed to make that work :slight_smile:

Disclaimer... I don't know if this will work or if this is the best way. Just trying to help...

In this thread they convert a Base64 string to a TJSUnit8Array so it's likely the same idea, just that your source is your Response.Result value. So maybe it looks a little bit like this?

 function ResponseToArrayBuffer(str: string): TJSArrayBuffer;
  var
    BufView: TJSUInt8Array;
    I: Integer;
  begin
    Result := TJSArrayBuffer.new(Length(str));
    BufView := TJSUInt8Array(Result);
    for I := 0 to Length(str) - 1 do
      BufView := TJSString(str).charCodeAt(I);
  end;

And you'd use it like this?

buf := ResponseToArrayBuffer(String(Response.Result));

Someone who's actually done this might be of more help, but I think that's the gist of it.

2 Likes