#1 2015-02-27 06:16:39

noobies
Member
Registered: 2011-09-13
Posts: 139

save picture from blob to server folder

hi, i use sample 10 - Background Http service.
is it possible use client side procedure to save the image from blob to server folder?

Offline

#2 2015-02-27 07:39:45

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

Re: save picture from blob to server folder

Yes, of course.
Use a method-based service, for instance.
See e.g. TNoteServer.Blob() method in sample "26 - RESTful ORM\RESTServerClass.pas".

Offline

#3 2015-02-27 14:31:29

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: save picture from blob to server folder

thanks, i see sample, but dont understand how it works. all samples have client and server files, but 26 - RESTful ORM\RESTServerClass.pas have only server side

Offline

#4 2015-02-28 09:46:04

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

Re: save picture from blob to server folder

Did you at least search in the documentation do get how REST works?

To consume it from a client, use a regular HTTP client, then call root/notefile/blob, you can retrieve a blob with GET, modify it with POST/PUT, and delete it with DELETE methods.
It is pretty clear when you look at the TNoteServer.Blob() method implementation.

Offline

#5 2015-03-02 07:14:12

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: save picture from blob to server folder

problem how "call root/notefile/blob"

i run server from 26 sample and if i run client i get "<h1>Bad Request (Invalid Hostname)</h1>"

/// minimal REST client for a list of Persons from RESTserver.exe
program RESTclient;

{$APPTYPE CONSOLE}

uses
  SynCommons,          // framework core
  mORMot,              // RESTful server & ORM
  mORMotHttpClient,    // HTTP client to a mORMot RESTful server
  SynGdiPlus,
  RESTData;           // data model unit, shared between server and client

var aModel: TSQLModel;
    aClient: TSQLHttpClient;
    aRootURI, response: RawUTF8;
    jpg: TJPEGImage;
    jpgRaw: RawByteString;
begin
  Gdip := TGDIPlusFull.Create;

  aModel := DataModel(aRootURI);
  try
    aClient := TSQLHttpClientWinHTTP.Create('localhost','888',aModel);
    jpg := TJPEGImage.Create;
    jpg.LoadFromFile('d:\scans\1.jpg');
    SaveAsRawByteString(jpg, jpgRaw, gptJPG);
    aClient.CallBackGet('root/notefile/blob', [], response, TSQLNoteFile);
    write(response);
    aClient.CallBackPut('root/notefile/blob', jpgRaw, response, TSQLNoteFile);
    write(response);
    write(#10'Press [Enter] to quit');
    readln;
  finally
    aModel.Free;
  end;

  Gdip.Free;
end.

Offline

#6 2015-03-02 07:52:19

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

Re: save picture from blob to server folder

'root' is part of the model , and 'notefile' is deducted from TSQLNoteFile.

Just try

aClient.CallBackGet('blob', [], response, TSQLNoteFile);

Offline

#7 2015-03-02 08:12:03

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: save picture from blob to server folder

before it was, but still does not work.

    aClient.CallBackGet('blob', [], response, TSQLNoteFile);
    write(response);
    aClient.CallBackPut('blob', jpgRaw, response, TSQLNoteFile);

dont understand why, please try run this client with sample 26 server.

Last edited by noobies (2015-03-02 08:12:51)

Offline

#8 2015-03-02 08:30:34

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

Re: save picture from blob to server folder

You have to specify an ID!
Your REST resource is not defined.

1. Create a REST resource - aNewID := aClient.Add(aNoteFile);
2. Handle the 'blob' method on this REST resource.

Offline

#9 2015-03-02 09:12:44

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

Re: save picture from blob to server folder

I've added a RESTClient GUI project to sample "26 - RESTful ORM".
See http://synopse.info/fossil/info/6fb0736f8a

Offline

#10 2015-03-02 10:17:50

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: save picture from blob to server folder

big big thanks for sample!

Offline

Board footer

Powered by FluxBB