Jump to content
Sign in to follow this  

RemObject JSON FileUpload

Recommended Posts

I'd like to upload a binary file:

  edtFichier.InputType := itFile;
  w3_setAttrib(edtFichier.Handle, 'accept', 'image/*');
  w3_setAttrib(edtFichier.Handle, 'capture', 'camera')

to a RO JSON server:

procedure TMyService.FileUpload(const fichier: ROAnsiString; const data: Binary);
    if (data <> nil) then
        System.IOUtils.TFile.WriteAllBytes( @'u:\data', data.ToArray())   
        System.IOUtils.TFile.WriteAllBytes(@'u:\data', new Byte[0]);

The sample code above is no working.  There is no .ToArray member for Binary.

Look like I should do some encoding, but I couldn't find any example. 
Isn't there still any component for this?


Share this post

Link to post
Share on other sites

That looks like Delphi code? Second snippet there? You have to look at the Smart classes and the RO imported classes and method-names.
If you look at the generated code after importing a RODL file, you will notice:

(* This codegen depends on RemObjectsSDK.js: file must be in "SmartMobileStudio\Libraries\" folder
* Usage:
*  var channel := TROHTTPClientChannel.Create("http://localhost:8099/JSON");
*  var msg     := TROJSONMessage.Create();
*  var service := TNewService.Create(channel, msg);
*  service.Sum(1, 2,
*    procedure(aResult: Integer)
*    begin
*      ShowMessage('Result = ' + IntToStr(aResult) );
*    end,
*    ROErrorCallback);
Note: in the above imported RODL file, the remote service is just called "NewService". You have to import the RODL file for your service stack.

Also make sure that you have a JSON channel on your native server.

You might want to look at our classes for dealing with memory and binary data, like System.Memory.Buffer. System.Memory.Allocation etc. since they will simplify working with raw data. The unit System.Types.Convert is also very important, it has a class called TDataType that allows you to encode between instrinsic types, memory and byte-arrays.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...