34 lines
1.1 KiB
Bash
34 lines
1.1 KiB
Bash
#!/bin/sh
|
|
|
|
inotifywait -m /out -e close_write |
|
|
while read PATH ACTION FILE; do
|
|
|
|
if [[ "${FILE}" == *.mp4 ]]
|
|
then
|
|
echo "Following PATH is selected: $PATH"
|
|
echo "Uploading following FILE: $FILE"
|
|
|
|
file_path="${PATH}${FILE}"
|
|
chunk_size="$CHUNK_SIZE"
|
|
id="${FILE%.mp4}"
|
|
|
|
file_size=$(/bin/stat -c%s "$file_path")
|
|
num_chunks=$(( (file_size + chunk_size - 1) / chunk_size ))
|
|
|
|
i=0
|
|
while [ $i -lt $num_chunks ]; do
|
|
echo "${i}"
|
|
echo "${id}"
|
|
echo "${num_chunks}"
|
|
/bin/dd if="$file_path" bs=$chunk_size skip=$i count=1 2>/dev/null | \
|
|
/usr/bin/curl --location "$UPLOAD_URL" \
|
|
--header "Authorization: Bearer $AUTH_TOKEN" \
|
|
--form "recording_id=${id}" \
|
|
--form "chunk_index=${i}" \
|
|
--form "total_chunks=${num_chunks}" \
|
|
--form "FILE=@-"
|
|
|
|
i=$(( i + 1 ))
|
|
done
|
|
fi
|
|
done
|