delphi - Upload file to DataSnap REST server via TStream -


i've built datasnap rest server using delphi xe2 , i've added server method uploading files via tstream :

function tservermethods.updateuploadfile(sfilename: string; uploadstream: tstream): string; 

i want able call number of different clients (android, ios etc) , i've been testing method using various rest clients such postman (chrome plugin). far cannot accept content http post body. whenever send post command following response :

{"error":"message content not valid json value."} 

i've tried using various different 'content-type' settings nothing seems work. looks though datasnap insisting on content being json? i've tried pasting valid json content area gave same error response.

has used tstream input parameter datasnap server method? should doing way? i've used tstream output parameter downloading files many times , works well, first attempt @ uploading.

update

i made quick delphi datasnap client test uploadfile server method , works great. used fiddler examine post command delphi client uses send tstream in content body, , noticed json array of integers (bytes) e.g. [37,80,68,70,45,49,46,51,13,10]. can see modify android/ios clients convert binary data byte array format before posting, overhead without. if datasnap streams raw binary when tstream return parameter, why can't stream raw binary input parameter?

it seems when adding content data request body in post command, datasnap server insists data json. why when using tstream input parameter, stream data converted json array of integers (bytes) delphi datasnap client. format size inefficient upto 3 digits per byte, plus comma, size of data being uploaded can grow as 4 times.

what have therefore done instead encode data upload in base64. server method looks :

function tservermethods.updateuploadfile(sfilename: string; base64data: tjsonobject): string; 

notice i'm wrapping base64 string in tjsonobject. because if specify string type, delphi datasnap client call method , attempt put whole base64 string in url path, causing 'connection closed gracefully' error. using tjsonobject forces datasnap use post , put data in content body. json object passed single pair object :

{"uploadeddata":"jvberi0xljmncixi48b5siwgtk3pay.........."} 

this way size of data uploaded smaller , faster transfer. i'd still prefer able stream raw data in content body datasnap doesn't allow this.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -