Reputation: 1
We are planning to large amount of folders (sites) within Alfresco into a local disk. I have been going through a lot of similar questions and tutorials but can't seem to understand how to initiate a download using the REST API. This is my first time using this, can I get a step-by-step approach on how to tackle this?
Upvotes: 0
Views: 1533
Reputation: 10538
Well there are many ways to download content out of Alfresco. If you have not already, I suggest looking at http://api-explorer.alfresco.com to understand the REST API.
You can download any object in Alfresco if you know its node reference. For example, suppose I have a file named test-0.txt and its node reference is as follows:
workspace://SpacesStore/0e61aa25-d181-4465-bef4-783932582636
I could use the REST API to download it, like this:
http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/0e61aa25-d181-4465-bef4-783932582636/content
So, one strategy would be to traverse the nodes you want to export and then invoke that URL to download them.
Starting in Alfresco 5.2.1, Alfresco added a new endpoint called downloads. With it, you can request a download consisting of an arbitrary number of node references. So, if I have the following files:
test-0.txt: workspace://SpacesStore/0e61aa25-d181-4465-bef4-783932582636
test-1.txt: workspace://SpacesStore/6bdac77f-8499-4be3-9228-9aabf80ba3e3
test-2.txt: workspace://SpacesStore/a6861c8f-8444-4bce-87a2-191c56b6ec7c
test-3.txt: workspace://SpacesStore/118121e9-bd92-4dec-9de7-062e374e5fb5
I could ask Alfresco to create a download object (the actual content will be in ZIP format) consisting of all four of those files, like this:
curl --location --request POST 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/downloads' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--data-raw '{
"nodeIds":
[
"0e61aa25-d181-4465-bef4-783932582636",
"6bdac77f-8499-4be3-9228-9aabf80ba3e3",
"a6861c8f-8444-4bce-87a2-191c56b6ec7c",
"118121e9-bd92-4dec-9de7-062e374e5fb5"
]
}'
Alfresco will respond with something like:
{
"entry": {
"filesAdded": 0,
"bytesAdded": 0,
"totalBytes": 0,
"id": "91456d9a-ed9e-493a-9efa-a1e49fbb578b",
"totalFiles": 0,
"status": "PENDING"
}
}
Notice that status of PENDING. It is asynchronously building the ZIP we asked for. You can check on it by doing a GET on the download object, like:
http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/downloads/91456d9a-ed9e-493a-9efa-a1e49fbb578b
Once the response comes back as DONE you can download the ZIP Alfresco prepared for you. Remember the node endpoint from the start of this post? It works here too. Just use the download ID in place of the node reference, like:
curl --location --request GET 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/91456d9a-ed9e-493a-9efa-a1e49fbb578b/content' --header 'Authorization: Basic YWRtaW46YWRtaW4='
So, rather than individually download every object you are trying to export you could batch them up and download multiple objects compressed as a ZIP.
If you don't want to do it with straight REST you might also consider using CMIS. You can get a client library for your preferred language at the Apache Chemistry project.
Upvotes: 2