Building Apps with Jigx
Data

File handling

11min
{{jigx}} stores files as local files on the device and returns the file's uri as the default value when saving these files to a datasource, you must convert files from the local uri to base64, data uri, or buffer the opposite is true when handling the files returned from the datasource; you must convert them from their saved state (base64, data uri, or buffer) to a local uri type of files images documents image files can be used in the following functionality data conversion configuration result rest provider calls with files add the conversion to the rest function get incoming save outgoing create outgoing update outgoing sql provider calls with files add the conversion to the rest function get incoming save outgoing create outgoing update outgoing datasource queries with files add the conversion to the datasource when using {{dynamicdata}} incoming actions with files add the conversion to the action when saving images and files outgoing the conversions property allows you to configure the file conversion to the required format core structure conversions this holds an array of properties that should be converted the following properties control the conversion \ property the name of the property to convert \ from format of the input data it can be buffer, base64, data uri, or local uri \ to format of the converted data it can be base64, data uri, buffer, or local uri \ convertheictojpg when set to true , and the file being converted is heic, it is converted to jpg conversions can be set up as a static array of definitions or dynamically as an array returned by an expression to set up dynamic conversions, use the expression conversions =@ctx datasources conversions , applicable to both local and global actions referencing files in a {{jig}} you can access the file using the state of the components and properties in a {{jig}} , such as media field docid\ klbuxur83js6ztfrznjva or avatar field docid\ auza3uj8vrna2pxdk1kbz when referencing files in {{jig}} s use the state value configuration for example file =@ctx components profilepicture state value image =@ctx components image state value considerations conversions should be configured within the sql and rest functions when the conversion is configured in the function, it stores the data as the 'from' type in the datasource when conversions are done at the datasource level, they are still stored in the datasource as their original value they are only converted after the fact when requested; however, the datasource value does not change do not load data back from buffer using the {{dynamicdata}} provider; the file will not show when saving images to {{dynamicdata}} consider the file size you can reduce the file size in the media field docid\ klbuxur83js6ztfrznjva by configuring the imagequality property use convertheictojpg to ensure images are visible on ios and android devices the property is available for rest and sql functions, {{dynamicdata}} and actions {{jigx}} does not recommend storing images in {{dynamicdata}} (via any conversion), as the max file size per record is 350k examples and code snippets examples and code snippets convert incoming data rest & sql function in the examples below, the file conversions are configured in the rest and sql (get) functions to convert the incoming files rest function in provider data provider rest method get format pdf #pdf indicates a generic binary type url https //graph microsoft com/v1 0/me/photo/$value outputtransform $ {"data" $ data,"userid" $ inputs userid value} #add the email input to the output to identify image later in select uselocalcall true parameters accesstoken location header required true type string value oauth microsoft #use manage jigx com to define credentials for your solution userid type string location path required true conversions \ property data from base64 to local uri sql function in provider data provider sql method query connection test db query select top(@top) id, firstname, lastname, avatarbase64, avatardatauri, avatarbuffer from employee parameters top location input required false type number value 10 conversions \ property avatarbuffer from buffer to local uri \ property avatarbase64 from base64 to local uri \ property avatardatauri from data uri to local uri convert outgoing data rest & sql function in the examples below, the file conversions are configured in the rest and sql (save/create/update) functions to convert the files that are outgoing to rest and sql rest function out provider data provider rest method patch url https //graph microsoft com/v1 0/me/photo/$value uselocalcall true parameters accesstoken location header required true type string value oauth microsoft # use manage jigx com to define credentials for your solution content type location header required true type string value image/jpeg # set the content type of the body file location body required true type image conversions \ property file from local uri to buffer sql function out provider data provider sql method execute connection test db procedure addwidget parameters firstname location input required true type string lastname location input required true type string avatarbase64 location input required true type string avatardatauri location input required true type string avatarbuffer location input required true type file encoding binary conversions \ property avatarbuffer from local uri to buffer \ property avatarbase64 from local uri to base64 \ property avatardatauri from local uri to data uri datasource conversion in this example, the {{dynamicdata}} image file conversion is configured in the datasource to convert the files to be used in the solution datasource conversion type datasource sqlite options provider data provider dynamic entities \ default/category query | select id, '$ name', '$ description', '$ image' from \[default/category] order by \[name] conversions \ property image from base64 to local uri action image conversion file conversions in actions can be configured with dynamic data, sql, and rest providers they can be set up as a static array of definitions or dynamically as an array returned by an expression to set up dynamic conversions, use the expression conversions =@ctx datasources conversions , applicable to both local and global actions execute entity action (static) type action execute entity options title save provider data provider dynamic entity default/category method save data id =@ctx jig inputs categoryid name =@ctx components name state value description =@ctx components description state value \# reference the image using an expression image =@ctx components image state value \# static conversion configuration conversions \ property image from local uri to base64 execute entity action (dynamic) type action execute entity options title save provider data provider dynamic entity default/category method save data id =@ctx jig inputs categoryid name =@ctx components name state value description =@ctx components description state value \# reference the image using an expression image =@ctx components image state value \# dynamic conversion configuration conversions =@ctx datasources conversions datasource type datasource sqlite options provider data provider dynamic entities \ default/category query | select id, '$ name', '$ description', '$ image' from \[default/category] order by \[name] conversions \ property image from base64 to local uri add multiple files with sql data provider this example uses the text field with mediatype image and ismultiple true to add multiple images to sql the conversion of the files is done in the sql function sql add widget multiple function jigx # add under function folder provider data provider sql method execute connection sportconnect procedure addmultipleavatar parameters avatarbuffer encoding binary location input required true type file description location input required true type string conversions \ from local uri property avatar to buffer sql get widget multiple jigx # add under function folder provider data provider sql method query connection sportconnect query | select id, description, avatar from avatarmulticonversion conversions \ property avatar from buffer to local uri add widget mutiple sql jigx # add under jig folder title add widget multiple type jig default onfocus type action sync entities options provider data provider sql entities \ entity avatarmulticonversion function sql get widget multiple datasources allimages type datasource sqlite options provider data provider local entities \ entity avatarmulticonversion query | select '$ id', '$ type', '$ avatar' from \[avatarmulticonversion] children \ type component form instanceid add widget multiple options children \ instanceid description options label description type component text field \ instanceid avatarbuffer options \# set for multiple files to be added ismultiple true label avatar mediatype image type component media field isdiscardchangesalertenabled false \ type component list options data =@ctx datasources allimages maximumitemstorender 8 item type component list item options title =@ctx current item type leftelement element image text "" uri =@ctx current item avatar actions \ children \# use execute entites for multiple files to be added \ type action execute entities \# options in error are expected as there are no functionparameters options title add widget multiple provider data provider sql entity avatarmulticonversion data | \=@ctx components avatarbuffer state value { "description" @ctx components description state value , "avatarbuffer" $ } function sql add widget multiple goback stay method functioncall onsuccess title success convert heic to jpeg in this example, the file conversion is configured in the rest function to convert the files that are outgoing via rest convertheictojpg is configured to true to convert heic images to jpeg which ensures images are visible on ios and android devices the property is available rest and sql functions, {{dynamicdata}} and actions provider data provider rest method patch url https //graph microsoft com/v1 0/me/photo/$value uselocalcall true parameters accesstoken location header required true type string value oauth microsoft # use manage jigx com to define credentials for your solution content type location header required true type string value image/jpeg # set the content type of the body file location body required true type image conversions \ property file from local uri to buffer convertheictojpg true see also media field docid\ klbuxur83js6ztfrznjva