-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.sh
executable file
·43 lines (36 loc) · 1.19 KB
/
upload.sh
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
#!/bin/sh
# Some nice variables
targetemail="[email protected]"
api_key="somekey"
server="rdl-share.ucsd.edu"
current_date=$(date -v +7d +%Y-%m-%d)
fullpath=$1
filename=`basename ${fullpath}`
if [ -z ${fullpath} ]; then
echo "You need to provide a filename."
exit
fi
if [ ! -f ${fullpath} ]; then
echo "Source file/path does not exist or is not accessible."
exit
fi
# Uploading the actual file and get attachment id for each file
# attachment_id=`curl -X POST --user "$api_key:x" -F Filedata=@$1 $server/attachments`
attachment_id=`curl -X POST --user "$api_key:x" -H "Accept: application/json" \
-H "Content-Type: application/json" --data-binary "@${fullpath}" \
https://${server}/attachments/binary_upload?filename=${filename} | cut -d ':' -f 3 | cut -d '"' -f 2`
echo $attachment_id
# Attach the file to a message in the inbox
cat <<EOF | curl -k -X POST -H "Accept: application/json" -H "Content-Type: application/json" --user "$api_key:x" -d @- https://${server}/message
{"message":
{
"recipients":["$targetemail"],
"subject":"File Upload",
"message":"File Upload",
"expires_at":"$current_date",
"send_email":false,
"authorization":3,
"attachments":["$attachment_id"]
}
}
EOF