As we learned, a gadget file cannot be created without an associated picture. If we tried we would get an error such as:
{
"error": {
"errorKey": "framework.exception.ApiDefault",
"statusCode": 422,
"briefSummary": "10190002 Found 1 integrity violations:\nThe association child multiplicity has been violated:
...
So we need to upload a gadget picture first.
Before uploading any files create a folder called My Gadgets under /Company Home (i.e. root). To do this we POST to the /nodes/{id}/children URL:
curl -H "Content-Type: application/json" -d '{"name":"My Gadgets","nodeType":"cm:folder"}' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children | jq
Now we can upload the gadget picture, prepare a PNG somewhere with the filename gadget-picture.png and then upload it as follows:
$ curl -X POST -F filedata=@gadget-picture.png -F "name=gadget-picture.png" -F "nodeType=cm:content" -F "relativePath=My Gadgets" -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 43532 0 701 100 42831 1070 65390 --:--:-- --:--:-- --:--:-- 66359
{
"entry": {
"isFile": true,
"createdByUser": {
"id": "admin",
"displayName": "Administrator"
},
"modifiedAt": "2019-10-21T09:32:53.121+0000",
"nodeType": "cm:content",
"content": {
"mimeType": "image/png",
"mimeTypeName": "PNG Image",
"sizeInBytes": 42303,
"encoding": "UTF-8"
},
"parentId": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3",
"aspectNames": [
"cm:versionable",
"cm:titled",
"cm:auditable",
"cm:author",
"exif:exif"
],
"createdAt": "2019-10-21T09:32:53.121+0000",
"isFolder": false,
"modifiedByUser": {
"id": "admin",
"displayName": "Administrator"
},
"name": "gadget-picture.png",
"id": "b8dc45cd-6828-41df-a908-e0fa8dbbd96b",
"properties": {
"exif:pixelYDimension": 340,
"cm:versionType": "MAJOR",
"cm:versionLabel": "1.0",
"exif:pixelXDimension": 340
}
}
}
Make a note about the Node Identifier for the gadget-picture.png file as we are going to need it in a bit. While we are at it we can also prepare two of the other associations that we can specify when we create a gadget node. Let’s first upload a gadget review. Create a text file called gadget-review.txt and upload it as follows to the My Gadgets folder:
$ curl -X POST -F filedata=@gadget-review.txt -F "name=gadget-review.txt" -F "nodeType=cm:content" -F "relativePath=My Gadgets" -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1212 0 638 100 574 2345 2110 --:--:-- --:--:-- --:--:-- 4472
{
"entry": {
"isFile": true,
"createdByUser": {
"id": "admin",
"displayName": "Administrator"
},
"modifiedAt": "2019-10-21T09:42:48.727+0000",
"nodeType": "cm:content",
"content": {
"mimeType": "text/plain",
"mimeTypeName": "Plain Text",
"sizeInBytes": 47,
"encoding": "ISO-8859-1"
},
"parentId": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3",
"aspectNames": [
"cm:versionable",
"cm:titled",
"cm:auditable",
"cm:author"
],
"createdAt": "2019-10-21T09:42:48.727+0000",
"isFolder": false,
"modifiedByUser": {
"id": "admin",
"displayName": "Administrator"
},
"name": "gadget-review.txt",
"id": "581baebd-3814-4cd0-884a-3179f2dac0ac",
"properties": {
"cm:versionLabel": "1.0",
"cm:versionType": "MAJOR"
}
}
}
Make a note about the Node Identifier for the gadget-review.txt file as we are going to need it too later. Next let’s also create a company node:
$ curl -H "Content-Type: application/json" -d '{"relativePath":"My Gadgets", "name":"Cool Gadgets Inc","nodeType":"fdk:company", "properties": {"fdk:email":"info@coolgadgets.com","fdk:url":"www.coolgadgets.com","fdk:city":"London"}}' -H 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 844 0 659 100 185 9835 2761 --:--:-- --:--:-- --:--:-- 12597
{
"entry": {
"isFile": true,
"createdByUser": {
"id": "admin",
"displayName": "Administrator"
},
"modifiedAt": "2019-10-21T10:01:55.279+0000",
"nodeType": "fdk:company",
"content": {
"mimeType": "application/octet-stream",
"mimeTypeName": "Binary File (Octet Stream)",
"sizeInBytes": 0,
"encoding": "UTF-8"
},
"parentId": "e2bdf9a3-ef31-469f-aeb4-07f2083961b3",
"aspectNames": [
"cm:auditable"
],
"createdAt": "2019-10-21T10:01:55.279+0000",
"isFolder": false,
"modifiedByUser": {
"id": "admin",
"displayName": "Administrator"
},
"name": "Cool Gadgets Inc",
"id": "5bae662a-b450-49c0-8f40-8ba2046aa423",
"properties": {
"fdk:email": "info@coolgadgets.com",
"fdk:city": "London",
"fdk:url": "www.coolgadgets.com"
}
}
}