Skip to content

Instantly share code, notes, and snippets.

@kmurugulla
Created May 2, 2017 17:30
Show Gist options
  • Save kmurugulla/21e7aed39bb9eabcf1fa5c22e3ca0515 to your computer and use it in GitHub Desktop.
Save kmurugulla/21e7aed39bb9eabcf1fa5c22e3ca0515 to your computer and use it in GitHub Desktop.
Script to create an asset node and upload associated binary into AEM
#! /bin/bash
#Author : Kiran Murugulla
#Description : Script to create an asset and upload binary from local machine into AEM
ROOT_PATH="content/dam/rrd/dsg"
ASSET_FULL_PATH="$ROOT_PATH/$3"
usage="Usage: uploadtest.sh \n aemserver:port (exclude http/s) \n adminuserid:adminpwd \n assetpath (relative to $ROOT_PATH) \n path/to/binary (on your local)\n"
START_TIME=$SECONDS
if [ ! $# -eq 4 ] ; then
echo -e "$usage"
exit 2
fi
echo -e "Creating Asset Node at - $ASSET_FULL_PATH"
#Create dam:Asset Node
curl -u "$2" -F jcr:primaryType=dam:Asset http://"$1"/"$ASSET_FULL_PATH" > /dev/null 2>&1
#Create dam:asset/jcr:content node
curl -u "$2" \
-F jcr:primaryType=dam:AssetContent \
-F cq:name="upload test" \
http://"$1"/"$ASSET_FULL_PATH"/jcr:content > /dev/null 2>&1
#Create metadata node
curl -u "$2" \
-F jcr:primaryType=nt:unstructured \
http://"$1"/"$ASSET_FULL_PATH"/jcr:content/metadata > /dev/null 2>&1
#Create renditions folder
curl -u "$2" \
-F jcr:primaryType=nt:folder \
http://"$1"/"$ASSET_FULL_PATH"/jcr:content/renditions > /dev/null 2>&1
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo -e "Completed creating $ASSET_FULL_PATH."
echo -e "Time took : $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec"
echo -e " Start uploading binary .."
#start uploading the binary
curl -u "$2" \
-X PUT \
-T "$4" \
http://"$1"/"$ASSET_FULL_PATH"
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo -e "Completed uploading binaries ."
echo -e " Time took : $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec \n"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment