DataSnap/REST - Upload image from client to server.

Hello,

I am having problem to trying to send a file or JSON class for the server.

The return of the server is "message content is not a valid json value".
I use Delphi XE5. 
Also, I'm using the RESTClient and RESTRequest components for the connection.

Below is my routine client and server.

{code}
{Call}
SendExame('C:\Users\xxx\Pictures\Image01.png');

{Client}
procedure SendExame(file_path: String);
var
  jsonObj: TJSONObject;
  mStream: TMemoryStream;
  aParam: TRESTRequestParameter;
begin
  jsonObj := TJSONObject.Create;
  try
    mStream := TMemoryStream.Create;
    try
      mStream.LoadFromFile(file_path);
      mStream.Position := 0;
      jsonObj.AddPair('file', IdEncoderMIME.EncodeStream(mStream));
    finally
      mStream.Free;
    end;

    RESTRequest1.Params.Clear;
    aParam             := RESTRequest1.Params.AddItem;
    aParam.Value       := jsonObj.ToString;
    aParam.ContentType := ctAPPLICATION_JSON;
  finally
    jsonObj.Free;
  end;

  RESTRequest1.method   := rmPost;
  RESTRequest1.Resource := 'UploadImage';
  RESTRequest1.Execute;
end;


{Server}
procedure TdtmServerMethods.updateUploadImage(jsonResult: TJSONObject);
var
  mStream: TMemoryStream;
begin
  mStream := TMemoryStream.Create;
  try
    TIdDecoderMIME.DecodeStream((jsonResult.Get('file').JsonValue as TJSONString).Value, mStream);
    mStream.Position := 0;
    mStream.SaveToFile('C:\Test.png');
  finally
    mStream.Free;
  end;
end;
{code}
0
Utf
6/8/2015 7:03:28 PM
embarcadero.delphi.webservices 976 articles. 0 followers. Follow

0 Replies
1107 Views

Similar Articles

[PageSpeed] 22

Reply:

Similar Artilces:

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...

Send Image Data from Android client to Datasnap Rest Server
I have an Android app that communicates to a Datasnap Rest Server for data exchange. The client collects data, including images and needs to store them on a SQL database on the server machine. I can send the related data no problem. My problem is working out how to send image data from the Android client to the server. I've looked at the various sample apps, but can't find anything that looks like what I need. Thanks ...

ANN: DataSnap-like Client-Server JSON RESTful Services in Delphi 7-2010 [Edit]
How to implement a very useful service... say... adding two numbers? In our framework, you code Server-Side: {code} function TSQLRestServerTest.Sum(aRecord: TSQLRecord; aParameters: PUTF8Char; const aSentData: RawUTF8; var aResp, aHead: RawUTF8): Integer; var a,b: Extended; begin if not UrlDecodeNeedParameters(aParameters,'A,B') then begin result := 404; // invalid Request exit; end; while aParameters<>nil do begin UrlDecodeExtended(aParameters,'A=',a); UrlDecodeExtended(aParameters,'B=',b,@aParameters); end; aRes...

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="UDPDSClinetstub.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="UDPDSClinetstub.zip" UEs...

Delphi 2009 Datasnap server and client
Hello, I am trying develop Datasnap server and client. I have a type TStringArray = array of string;. I used this type in one of server method. When I am trying to Generate Datasnap Client classes it says 'Remote error:Unknow data type: TStringArray'. How can I register this data type? -- Best Regards Md. Shariful Alam Khan Hello, Isn't there anyone to answer my question? Also I am getting same error if I use TStrings or TWideStringArray. Best Regards Md. Shariful Alam Khan "Md. Shariful Alam Khan" <murad_mouri@yahoo.com> wrote in messag...

Reading a TDataset from a REST server in a Delphi Client
Hi, I wrote a REST Server in XE2 - that generally works fine - and I am able to use it from a Javascript client. We also wanted to use it in a Delphi client - and I have never written code with a Delphi client that accepts a dataset from a REST server. Basically, when I call my proxy (my Delphi code is in Delphi XE, where our client application is) - I get an error message, EDatabaseError 'Missing query, table name or procedure name' Any ideas what this is all about? I tried to replace the TDataset with a TClientDataset and the problem is the same. Any ideas where to con...

Delphi xe datasnap rest server and serverside scripting
Hi all, I'm trying to use serverside scripting using the standard datasnap rest server produced automatically by Delphi but I can't figure out how to do that. Here is what I do: I create a new DataSnap Rest Application (standalone vcl app.) with all the standard choices selected. After that I want to change the ReverseString.html code so that it writes (for example) "hello word" To do that I Insert inside the html file the following script: <%= hello word %> I also set the scriptengine field of the pageproducer of the html page to the Jscript value (so that it...

REST Datasnap Server seperate Callback to multiple clients
I have a REST server that send a callback messages to the clients. Each channel get named with an int value. Channel1 -> Client1 Channel2 -> Client2 It is initiated by a common procedure an being broadcast over the SDServer, but if I inciate this call form two clients at once, just one of them gets updated and the latter have to wait for the prior to complete. Is there a way around this? ...

DataSnap REST Server/Client LifeCycle Session does not work
Hello, in this post http://edn.embarcadero.com/article/41289 the LifeCycle management is described. If I test this with a DataSnap REST Server and Client the LifeCycle "session" will always create/free my DSServerClass (and generate an other GUID). Is this is a bug or a limitation of the REST architecture? (Delphi XE3) Regards Mathias Pannier Am 13.06.2014 14:02, schrieb Mathias Pannier: > in this post http://edn.embarcadero.com/article/41289 the LifeCycle > management is described. If I test this with a DataSnap REST Server and > Client the LifeCycle &quo...

Blob Field through DataSnap Client/Server Delphi 2009
I can't pass Blob Field through DataSnap Client/Server Delphi 2009, when I try to Open the TSqlServerMethod this says Remote Error: unexpected metadata type, but, that only when the Table or Query have Blob fields. > {quote:title=ALEXANDER DAVID CRUZ MARQUEZ wrote:}{quote} > I can't pass Blob Field through DataSnap Client/Server Delphi 2009, when I try to Open the TSqlServerMethod this says Remote Error: unexpected metadata type, but, that only when the Table or Query have Blob fields. Hi. I have exactly the same problem. Seems it's not a just an error but it's a D...

Iphone monotouch client <-> Delphi 2010 datasnap server
So, Monotouch has been released and it is now simpler to get into making iphone apps (and soon also android apps). But what is the easiest way to tie an monotouch developed iphone client to a delphi 2010 datasnap server? Any ideas? Rant: "Monotouch" should have been a delphi tool. Then it would have flown of the shelves! But noooo. Not even in the next version is such fat clients and native compiled enviroments catered for. Instead there are talks about linux, mac os, etc. *sigh* Rants are not productive and kill one's desire to be helpful. Fortunately, I decided to...

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...

Upgrading Delphi 7 Datasnap to XE: client fails to connect to server [Edit]
Hi, I'm currently working on upgrading a codebase from Delphi 7 to XE, and am currently just trying to get an older school Datasnap application working under XE. For reference: I'm developing/testing on Windows 7 64bit and currently using Delphi XE. The client application connects to the app server via a socket connection currently, and thus uses Borland Socket server, which includes using a registered "Interceptor" which does data compression/decompression. Now the problem: Currently I'm running into a problem trying to get the client to actually talk to t...

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 } ...

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...

Web resources about - DataSnap/REST - Upload image from client to server. - embarcadero.delphi.webservices

Companies Directory - Job Fusion
D1 Locker D2L D4D Technologies DAA Deutsche Auftragsagentur Dabble Dabble DB Dabee Dabizmo DabKick Dabo Health Dacentec Dachis Group ...

Embarcadero Webinars
Advanced software tools for application developers and database professionals. Cross-platform solutions for database design, development and ...

David I - Head is in the cloud, feet planted firmly in the ground
... I’s (David Intersimone) Embarcadero blog about programming, languages, databases, history, and more. , and filed under Cloud Computing , DataSnap ...

RAD Studio 2015 Roadmap
Rad Studio, Delphi, C++Builder, and Appmethod 2015 Technology Roadmap from JT at EmbarcaderoTechnologies

FireMonkey Q&A
Questions and answers from a FireMonkey webinar

Contact Us - Ginktage
Home Privacy Policy Contact Us Home .NET Events Microsoft Office SQL Server Tools Gadgets Technology Tips&Tricks Contact Us Ginktage Learn , ...

News Briefs: December 15, 2008 - SD Times: Software Development News
AccuSoft creates an SDK for Web imaging software, while Artisan releases a free version of Artisan Studio. Also, Bredex, Embarcadero, Ilog and ...

Craig Stuntz’s Weblog : Site Map
Craig Stuntz’s Weblog F# • Compilers • Programming Languages • Functional Programming • Web Skip to content Home About Site Map Site Map Share ...

iBeacon Hack Makes It More Efficient To Wait Tables
Here at the 2014 TechCrunch Disrupt SF hackathon two-man hack team, Ray Ho and Mark Watson, showed off a simple but promising concept that combines ...

Te Waka o Delphi · Poll Archives
Keeping Delphi afloat in Aotearoa

Resources last updated: 12/24/2015 10:36:15 AM