Create a File from a Base64-encoded String
The File type has a special property called base64Data
which can be used to supply the binary data for a file in a Base64-encoded string.
By simply including base64-encoded data in the property base64Data
and POSTing to a type inheriting from File
you can create files with that content.
The following example will create a 16x16 PNG image icon of the smallest Structr logo. Note that we are sending the POST request to the Image
resource.
$ curl -si -HX-User:admin -HX-Password:admin http://localhost:8082/structr/rest/Image -d "{name:'structr_16x16.png', base64Data:'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAAHnlligAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAAd0SU1FB9sFHRYML8Fx6+kAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAABhElEQVQoz4WRv4rCQBDG51YFJaSIjUWwiOALiBNBwUK0s7Cz0VYLS9/AN7ALWFopgqWgtSBib6FoEyxsRDERV8JcsTmJIXf3q+bPfvPNsF+ICACAiJZlfYmMAQBjDBDxcDggIiKGVFW93W6ZTKZYLLrvBAw8MADIZrP9ft9NNE2TJMm1QMThcEg/lEolRAwLpaIojuNUKpX7/S4qHy4A0Ov1TqeTYRiuolqtxuNxANhut6PRKEDxJgwAkUhkPp+LZY7HY71edxvRaFSSJF3X/Ydwzomo0Wj4G8/ns1wup9Pp5XKZz+eD112v12Kma16r1QK2AoBYLCaCdrsdMEpRFF3XE4mEV3q9XmezGef8YxIAyLJsGIamadPpdL/fv+uPx4OI/NZeJpPJbreDXwipqioizvlqtZJludVqdTodRCSiy+Vi27ZXEPwXjLFcLtftdpPJpG3bzWbTNE2/gxciMk1zPB6/Xq9CoWBZ1mazCTh6MBikUimv0nGc8/m8WCz+WekPvgFa7Z9k8DjEZAAAAABJRU5ErkJggg=='}"