3 [ "$include_upload" ] && return 0
8 local boundary line length=0
10 [ ! "${CONTENT_TYPE}" -o "${CONTENT_TYPE##multipart/form-data;*}" ] && return 1
12 boundary="${CONTENT_TYPE#*; boundary=}"
13 boundary="${boundary%%;*}"
15 while read -r line; do
16 length="$(( length + ${#line} + 1))"
17 [ "${line%${CR}}" = "--$boundary" ] && break
19 while read -r line; do
20 length="$(( length + ${#line} + 1))"
21 [ ! "${line%${CR}}" ] && break \
25 printf "%i\n" "$(( CONTENT_LENGTH - length ))" >"${file}.upload"
26 head -c "$(( CONTENT_LENGTH - length ))" \
28 # print lines until boundary ( = actual file upload)
30 /^--'"${boundary}"'(--)?\r?$/!bFILE;
31 # discard remaining lines
34 truncate -s $(( $(stat -c %s -- "$file") -2 )) -- "$file"
35 rm -- "${file}.upload"
41 [0-9]) printf %i "$num";;
48 *) printf '%s%s' "$(base16 $((num / 16)))" "$(base16 $((num % 16)))"
54 printf '%s\r\n%s\r\n' "$(base16 "${#chunk}")" "$chunk"
57 frame_uploadprogress() {
58 printf '%s: %s\r\n' "Content-Type" "text/html" "Transfer-Encoding" "chunked"
61 HTTP_CHUNK "<!DOCTYPE HTML>
63 <title>Upload Progress</title>
64 <!-- <link rel=\"stylesheet\" type=\"text/css\" href=\"$_BASE/rawnet.css\" /> -->
65 <style type=\"text/css\"><!--
68 background: transparent;
71 #uploadprogress .progress {
75 width: 99%; width: calc(100% - 2pt);
76 background-color: #FFF;
81 #uploadprogress .progress .bar {
84 left: 0; top: 0; bottom: 0;
85 background-color: #666;
87 #uploadprogress .progress .count {
90 left: 0; top: 0; right: 0; bottom: 0;
94 " "</head><body id=uploadprogress>
96 HTTP_CHUNK ' <div class=progress><div class=bar style="width: 0%;"></div><div class=count>0 / 0</div></div>'
97 while [ ! -f "${VIDEO_FILE}" -a ! -f "${VIDEO_FILE}.upload" ]; do
100 read size <"${VIDEO_FILE}.upload" 2>&-
101 while [ -f "${VIDEO_FILE}.upload" ]; do
102 stat="$(stat -c %s "$VIDEO_FILE" 2>&-)"
103 HTTP_CHUNK " <div class=progress><div class=bar style=\"width:$(( stat * 100 / size))%;\">" \
104 "</div><div class=count>$((stat / 1048576))MB / $((size / 1048576))MB</div></div>" "$BR"
107 HTTP_CHUNK ' <div class=progress><div class=bar style="width:100%%;"></div><div class=count>Ready!</div></div>' "$BR" \