32 lines
1,012 B
Bash
32 lines
1,012 B
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=$(stat -c%s "$file_path")
|
|
num_chunks=$(( (file_size + chunk_size - 1) / chunk_size ))
|
|
|
|
i=0
|
|
while [ $i -lt $num_chunks ]; do
|
|
offset=$(( i * chunk_size ))
|
|
dd if="$file_path" bs=$chunk_size skip=$i count=1 2>/dev/null | \
|
|
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
|