DataSnap - Streaming JPEG Files via TStream From Server To Client (XE2)


I've written a DataSnap server method that returns a TStream object to transfer a file. The client application calls the method and reads the stream to download the file. The server method is very simple :

function TServerMethods.DownloadFile(sFilePath: string): TStream;
  strFileStream: TFileStream;
  strFileStream := TFileStream.Create(sFilePath, fmOpenRead);
  Result := strFileStream;

It works fine downloading many file types (PDF, GIF, BMP, ZIP, EXE) but it doesn't work when downloading JPG files. On the client side the stream object returned from the method call is always 0 in size with JPGs. I can successfully stream JPG files locally on my PC, so it must be something to do with DataSnap. I've done some research which suggests DataSnap converts the stream to JSON behind the scenes and there could be a problem with this when it comes to JPG files - can anybody confirm this? On the cl
ient side I'm using the TDSRESTConnection to call the server method. I realise I could ZIP the JPG files before streaming, but would rather not have to do this.

Any help appreciated.

2/6/2012 5:49:18 PM
embarcadero.datasnap 643 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 33

Thought I'd update the thread on my attempts to resolve this.  I never found a way to transfer a JPEG file over DataSnap using TStream, but have done it by converting the stream to a TJSONArray and passing this back instead.  So my server method now looks as follows :

function TServerMethods.DownloadJPEGFile(sFilePath: string): TJSONArray;
  strFileStream: TFileStream;
  strFileStream := TFileStream.Create(sFilePath, fmOpenRead);
  Result := TDBXJSONTools.StreamToJSON(strFileStream, 0, strFileStream.Size);

then at the client end I convert back to a TStream with :

strFileStream := TDBXJSONTools.JSONToStream(JSONArray);

I have created this as a new server method call purely for downloading JPEGs, as I've found transferring the files using TJSONArray instead of TStream is as much as 4 times slower, so I use my original method for all other file types.

2/9/2012 4:54:26 PM
As a further update, I've found this problem is related to regional settings on the client PC.  My system locale is set to "English (United Kingdom)" and the error also occurs with "English (United States)".  If I change the locale to "Japan (Japanese)" then the errors disappear.  The problem also affects Microsoft Word (.DOC) files as well as JPEGs.  I've submitted a QC report to Embarcadero :

3/27/2012 8:11:19 AM
This error (which also affects .DOC files) can be fixed by editing one of the DataSnap framework files :

1 .copy '...\RAD Studio\9.0\source\data\datasnap\Datasnap.DSClientRest.pas' to your DataSnap Client project folder
2. add the .pas file to the project
3. modify Line#1288 as below

//  LResponseJSON := TJSONObject.ParseJSONValue(BytesOf(LResponseText.StringValue), 0);
  LResponseJSON := TJSONObject.ParseJSONValue(BytesOf(UTF8String(LResponseText.StringValue)), 0);

4. rebuild DataSnap REST Client project
5. run it with REST Server
4/3/2012 12:33:47 PM

Similar Artilces:

XE Datasnap Client expection with a XE2 DataSnap Server.
I have developed a simple DataSnap Server on XE2 and the client that connects to this server is under XE. Everything works just fine except when freeing the ClientProxy Module on the client side I get the following exception " TDXError with message Invalid Ordinal 3." followed by a AV. Any hints how to avoid this exception or the Server must be on XE also? Thanks in Advance, Omar Zelaya I have now the DataSanp Server on XE and the client no longer throws the exception. So the question now is, it is possible to use a XE DataSnap Client with a XE2 DataSnap Se...

Indy 10
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_39eb5.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" The udp client component would be used in the datasnap server. The udp server component would be used in the datasnap client. --JivePart=_39eb5.zeB8CwDOH5aMJzMl Content-Type: application/x-zip-compressed; name="" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="" UEs...

Upload file to DataSnap REST server via TStream
Hi, I've built a DataSnap REST server using Delphi XE2 and I've added a server method for uploading files via TStream : {code}function TServerMethods.updateUploadFile(sFilename: string; UploadStream: TStream): string;{code} I want to be able to call this from a number of different clients (Android, iOS etc) and I've been testing the method using various REST clients such as Postman (Chrome plugin). However so far I cannot get it to accept the content for the HTTP POST body. Whenever I send the HTTP POST command I always get the following response : {code}{"error":...

Datasnap Rest client and no datasnap server
Hi, it's possible to use a delphi datasnap rest client to consume a rest web services written in other lenguages (like java or php) or i have to use an idhttp (or other) component? Thanks. Bye Pasquale Di Giovanni wrote: > > it's possible to use a delphi datasnap rest client to consume a rest > web services written in other lenguages (like java or php) or i have > to use an idhttp (or other) component? You could in theory, but it may be more trouble than its worth. You'd probably have to have control of the REST server so you can implement all the...

Android Client And DataSnap Server XE2
Hi, I'm doing some tests on Android to call a DataSnap server method that returns a simple class. Delphi Side: TPrueba = class private FUnString : string; public published property UnString : string read FUnString write FUnString; end; Java Side: private class TPrueba { public String UnString; } With the following Datasnap server method: function RetornaEstructura(Value : string) : TPrueba; When I generate the proxy the method returns a TJSONObject. 1. Is the Java class definition ok to match the Delphi one...

Connect Old Datasnap Clients with new datasnap Server ? [Edit]
Is it possible to connect a XE5 datasnap server with Borland C++ 6 Datasnap clients ? I want to know this before starting ... Edited by: Bart vd Voort vd Kleij on Jan 9, 2014 11:49 PM Edited by: Bart vd Voort vd Kleij on Jan 9, 2014 11:51 PM ...

Download file from datasnap server to android client
Hello all: I've a Datasnap Rest Server application works fine with android client . I need download files (many size 10 MB, 20 MB, 40 MB) from datasnapserver to Android client with a progressbar indicator. How to?. Thanks, in advance. Alfonso Maybe this is now possible for all platforms.. ...

DataSnap XE2 , is this bug in datasnap ?
Hello I create small datasnap server , the lifecycle=session , the problem is : Create client and put tow sqlconnection in form or datamodule , and connect to that server , when made call , the methods in servermethods (may or may not) one of the servermethod class is destroy , many ways to call methods in both connections but the class is destryed in server. I trace and debug every thing possible but nothing wrong . I test these on xp ( sometimes problem is on ) I test on win7 same as above I test on Server2003 , the same I test on server 2008 , the same I test it as Delphi im...

XE3 - DataSnap - server - HTML client
i need to any one to help me to upload and download file throw datasnap server and html - javascript. Hi ahmed, Delphi ships with sample located in: C:\Users\Public\Documents\RAD Studio\11.0\Samples\Delphi\DataSnap\FishFacts\. There you will find example of download image from DataSnap server to HTML - JavaScript client. Best regards, Erwin > {quote:title=Erwin Mouthaan wrote:}{quote} > Hi ahmed, > > Delphi ships with sample located in: C:\Users\Public\Documents\RAD Studio\11.0\Samples\Delphi\DataSnap\FishFacts\. > > There you will find example of downloa...

Delphi XE2 DataSnap Server
I'm building an XE2 DataSnap server which will serve connections from REST clients. My DSServerClass LifeCycle property is set to 'Invocation'. What I want to do is to log the details of all client connections to the server, including the following details : username, IP address, protocol, application name. I can currently get these details using the following events : DSAuthenticationManager - UserAuthenticate() : username, protocol (using the standard parameters passed in) DSServer - Connect() : protocol, IP address, application name (using DSConnectEventObject.ChannelInf...

DataSnap : client switches from dead server to alive server
I am very new of this thing: DataSnap , client-server application. I need solution about 2 servers. When one of them crashes, client just gets error message and user simply changes to another server, such as type 'server name'. First, I use 'LoadParamsFromIniFile' every time I start to connect, but it does not work. Anyone can show me some lines of code to solve my problem or some suggestions? PS. I am using XE3 with embedded component. Thank you Hi there, I just got an answer by doing this:- declare.... private { Private declarations } ...

How can I use a linux server as a proxy between a DataSnap server/client
I have a DataSnap Server that is behind a NAT firewall. I also have many DataSnap clients that need to connect to that server. I want to provide a connection proxy to help those two computers connect and transfer data. The server will be authorized for this service ahead of time and I thought the best way would be to have a dedicated port on my Linux servers IP for each server needing my connection service. I have thought about L2TP type of VPN connection from the server to my linux server. It would be nice if I could create scripts/batch files on both ends to automate the install and make th...

How to know which client using the server methord in Datasnap Server? [Edit]
Hi, There are some clients which has connected the datasnap server. I have recorded their ChannelInfo.Id when these clients connect the server in Onconnect Event of Datasnap Server. Now if a client is preparing to use the Server Methord, how can I get this client's thread id or ChannelInfo.Id? I want to do this: 1.So I can record the time of this client invoked the server methord in Datasnap Server. 2.So I can disconnect this client's connection. Best regards, Sunstone Edited by: sun stone on Feb 7, 2010 10:17 PM I want this to store session info in a server having...

DataSnap: Disconnecting a client from the server
Hello everybody, I encounter situations when a client connection shoud be dropped by the Server's action in spite of successful authentication/authorization completed. One example of such situation: Access to the same account should be restricted to only one connection at a time. A user did not close the client on one computer, then moved to another place and wishes to work from another location. The old connection should be shut down without any action taken by the 'old' client. Another example is abnormal shudown of the client, which entails the necessity to cleanup its...

requirements on server and client machine for DataSnap
Hi all, I think i am a little bit confused about multi tier. I have done a lot of research about the topic and came across thin (or zero) clients. I learned that thin clients need a transaction server on the server machine to handle the communication. Now I am not sure about DataSnap with a "fat" client. what are the requirements for using DataSnap with thin and / or fat clients? - Do I need a transaction server and thus a Server version of Windows? - Is there anything - further than what comes with Delphi - necessary to run a 3 tier application? - how do I choose the ...

Web resources about - DataSnap - Streaming JPEG Files via TStream From Server To Client (XE2) - embarcadero.datasnap

Streaming media - Wikipedia, the free encyclopedia
... is usually applied to media that are distributed over telecommunications networks , as most other delivery systems are either inherently streaming ...

Ustream Broadcast For Friends Live Video-Streaming App Adds Support For Facebook Pages
Streaming-video provider Ustream released an update to its Broadcast for Friends iPhone application that allows page administrators to record ...

NASA SDO - Streaming Plasma - NASA Solar Dynamics Observatory (Little SDO) - Facebook
SDO zoomed in on this active region to watch as plasma streamed back and forth above it over two days (Apr. 30 to May 2, 2011). Magnetic forces ...

Facebook’s Music Dashboard Could Unite the Fractured Streaming Market
Facebook is preparing partnerships with several online music services including Spotify that will be hosted in a music dashboard, GigaOm reports ...

Argus Streaming News (@ArgusRadio) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

GoodPlayer - Movie Player & Downloader & Streaming Media Player on the App Store on iTunes
Get GoodPlayer - Movie Player & Downloader & Streaming Media Player on the App Store. See screenshots and ratings, and read customer reviews. ...

Netflix beats HBO as streaming revolution reflected in Golden Globe nominations
Streaming services stormed the Golden Globe television nominations on Thursday with new shows such as Narcos and Mozart in the Jungle, turning ...

Yahoo’s new Video Guide app offers universal search across streaming services
Yahoo today released a new “Yahoo Video Guide” app for mobile devices that acts as one central location for users to find content from across ...

Google Play Movies & TV updated w/ AirPlay support, cellular streaming, more
... Movies & TV app, AirPlay it to your Apple TV, and continue using your iOS device as normal. Next, the update adds support for cellular streaming. ...

Apple Music declares war on streaming music rivals with new Taylor Swift exclusivity deal
... during the service's free period. Unfortunately, the end result was her wildly popular 1989 album becoming an Apple Music exclusive for streaming. ...

Resources last updated: 12/14/2015 9:45:18 PM