From: Denis Vlasenko Date: Thu, 17 Apr 2008 12:35:09 +0000 (-0000) Subject: httpd: add an example of POST upload CGI X-Git-Tag: 1_11_0~331 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=250aa5bb015061787e62f63847df04f377af91c1;p=oweals%2Fbusybox.git httpd: add an example of POST upload CGI --- diff --git a/networking/httpd_post_upload.txt b/networking/httpd_post_upload.txt new file mode 100644 index 000000000..a53b11467 --- /dev/null +++ b/networking/httpd_post_upload.txt @@ -0,0 +1,76 @@ +POST upload example: + +post_upload.htm +=============== + + +
+File to upload: +
+ + +post_upload.cgi +=============== +#!/bin/sh + +# POST upload format: +# -----------------------------29995809218093749221856446032^M +# Content-Disposition: form-data; name="file1"; filename="..."^M +# Content-Type: application/octet-stream^M +# ^M <--------- headers end with empty line +# file contents +# file contents +# file contents +# ^M <--------- extra empty line +# -----------------------------29995809218093749221856446032--^M + +# Beware: bashism $'\r' is used to handle ^M + +file=/tmp/$$-$RANDOM + +# CGI output must start with at least empty line (or headers) +printf '\r\n' + +IFS=$'\r' +read -r delim_line + +IFS='' +delim_line="${delim_line}--"$'\r' + +while read -r line; do + test "$line" = '' && break + test "$line" = $'\r' && break +done + +# This will not work well for binary files: bash 3.2 is upset +# by reading NUL bytes and loses chunks of data. +# If you are not bothered by having junk appended to the uploaded file, +# consider using simple "cat >file" instead of the entire +# fragment below. + +while read -r line; do + + while test "$line" = $'\r'; do + read -r line + test "$line" = "$delim_line" && { + # Aha! Empty line + delimiter! All done + cat < + +File upload has been accepted +EOF + exit 0 + } + # Empty line + NOT delimiter. Save empty line, + # and go check next line + printf "%s\n" $'\r' -vC >&3 + done + # Not empty line - just save + printf "%s\n" "$line" -vC >&3 +done 3>"$file" + +cat < + +File upload was not terminated with '$delim_line' - ??! +EOF