Alfresco uploader with Curl

Let see a simple shell script example to upload content to Alfresco repository using RESTful API.

Requires Curl package to be installed on your system. Just set ALFRESCO_SERVER, USERNAME and PASSWORD variables in script before start it…

#!/bin/bash
#
# Alfresco upload script with CURL by LouiSe@louise.hu
#
# Usage: alfresco_uploader.sh    
#
# ./alfresco_uploader.sh /tmp/some.pdf someSite documentLibrary someDir
#

ALFRESCO_SERVER=http://localhost:8080/alfresco
USERNAME="admin"
PASSWORD="admin"

#CURL_VERBOSE=-v
CURL_VERBOSE=-s
CURL_METHOD=POST
FILENAME=`basename $1`
MIMETYPE=`file --brief --mime-type $1`
CONTENTTYPE="cm:content"
UPLOAD_SERVICE_URL=${ALFRESCO_SERVER}/service/api/upload

echo "Uploading: ${FILENAME} ($MIMETYPE) to ${ALFRESCO_SERVER}"

curl ${CURL_VERBOSE} -k -X ${CURL_METHOD} \
    --user "${USERNAME}":"${PASSWORD}" \
    -F filedata=@$1 -F siteid="$2" -F containerid="$3" \
    -F uploaddirectory="$4" \ -F filename="${FILENAME}" \
    -F contenttype=${CONTENTTYPE} "${UPLOAD_SERVICE_URL}" \
    | grep 'description' | cut -d ':' -f 2 | tr -d '\"'

Example:

$./alfresco_uploader.sh ~/Desktop/advanced-workflow-article.pdf demo documentLibrary someDir
Uploading: advanced-workflow-article.pdf (application/pdf) to http://localhost:8080/alfresco
 File uploaded successfully
 

3 thoughts on “Alfresco uploader with Curl”

  1. Thank you very much for your very helpful script. No examples are available for Alfresco RESTful API. :-)) Cool !!

Leave a Reply

Your email address will not be published. Required fields are marked *