From: Paul Hänsch Date: Fri, 15 Apr 2022 11:13:42 +0000 (+0200) Subject: handling of binary file uploads X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=e52003a2f0aecacd91af213b8f5b777022d3a104;p=shellwiki handling of binary file uploads --- diff --git a/multipart.sh b/multipart.sh index 70270f6..09e3ca8 100644 --- a/multipart.sh +++ b/multipart.sh @@ -37,7 +37,7 @@ multipart(){ local name="$1" count="${2:-1}" local formdata state=begin - while read -r formdata; do case "$formdata" in + while IFS='' read -r formdata; do case "$formdata" in "--${multipart_boundary}--${CR}") [ $state = data ] && return 0 \ || return 1 @@ -52,12 +52,13 @@ multipart(){ [ $state = data ] && printf "%s\n" "$formdata" ;; "${CR}") - [ $state = dheader ] && state=data + if [ $state = dheader ]; then + sed -n "/--${multipart_boundary}\(--\)\?${CR}/q; p;" \ + | head -c-2 + return 0; + fi [ $state = header ] && state=junk ;; - *) - [ $state = data ] && printf "%s\n" "$formdata" - ;; esac; done <"${multipart_cachefile}" } @@ -79,8 +80,6 @@ multipart_filename(){ "${CR}") [ $state = header ] && state=junk ;; - *): - ;; esac; done <"${multipart_cachefile}" filename="${formdata#*; filename=\"}"