From e52003a2f0aecacd91af213b8f5b777022d3a104 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Fri, 15 Apr 2022 13:13:42 +0200 Subject: [PATCH] handling of binary file uploads --- multipart.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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=\"}" -- 2.39.2