]> git.plutz.net Git - shellwiki/commitdiff
handling of binary file uploads
authorPaul Hänsch <paul@plutz.net>
Fri, 15 Apr 2022 11:13:42 +0000 (13:13 +0200)
committerPaul Hänsch <paul@plutz.net>
Fri, 15 Apr 2022 11:13:42 +0000 (13:13 +0200)
multipart.sh

index 70270f68f1c3f91830af52e22847f6887ee27081..09e3ca8f256fd1bd598c9175150eb74aa78e7762 100644 (file)
@@ -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=\"}"