Jump to content
Sign in to follow this  
DidierXT

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);
begin
    if (data <> nil) then
        System.IOUtils.TFile.WriteAllBytes( @'u:\data', data.ToArray())   
    else
        System.IOUtils.TFile.WriteAllBytes(@'u:\data', new Byte[0]);
end;

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×