-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudinary.bash
More file actions
45 lines (35 loc) · 1 KB
/
cloudinary.bash
File metadata and controls
45 lines (35 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# ------------------------------
# Input parameters
fileName=$1
dbName=$2
cloudName=$3
apiKey=$4
apiSecret=$5
folder=${6:-""}
# ------------------------------
timestamp=$(date +%s)
publicId=$(basename $fileName)
publicId=${2:-$publicId}
if [ ! -z $folder ]; then
folderStr="folder=${folder}"
else
folderStr=""
fi
datatobehashed="access_mode=authenticated&${folderStr}&public_id=${publicId}×tamp=${timestamp}$apiSecret"
hash=$(echo -n ${datatobehashed} | sha1sum | awk '{print $1}')
commandArr=()
commandArr+=("curl -s -X POST https://api.cloudinary.com/v1_1/${cloudName}/auto/upload")
commandArr+=("-F \"file=@${fileName}\"")
commandArr+=("-F \"access_mode=authenticated\"")
commandArr+=("-F \"public_id=${publicId}\"")
if [ ! -z $folder ]; then
commandArr+=("-F \"${folderStr}\"")
fi
commandArr+=("-F \"api_key=${apiKey}\"")
commandArr+=("-F \"timestamp=${timestamp}\"")
commandArr+=("-F \"signature=${hash}\"")
commandArr+=("> /dev/null")
commandStr="${commandArr[@]}"
eval $commandStr
exit 0