4 bnd="${CONTENT_TYPE/*boundary\=/}"
6 awk -v "want=$1" -v "bnd=$bnd" '
9 # reset based on boundaries
10 $0 == "--"bnd"" { st=1; next; }
11 $0 == "--"bnd"--" { st=0; next; }
12 $0 == "--"bnd"--\r" { st=0; next; }
14 # search for wanted file
15 st == 1 && $0 ~ "^Content-Disposition:.* name=\""want"\"" { st=2; next; }
16 st == 1 && $0 == "" { st=9; next; }
18 # wait for newline, then start printing
19 st == 2 && $0 == "" { st=3; next; }
22 ' | head -c $((128*1024)) # Limit size to 128K