Re: Receiving a POSTed file
- Posted by bugmagnet May 06, 2014
- 1473 views
Okay, it's stopped working completely and I can't figure out why. I get either 404 or 502 errors. Just now I tried sending a 2GB ISO file and crashed Firefox completely (pretty cool, no?)
If anyone's got an idea why this is failing, please post.
include std/io.e include std/get.e include std/regex.e as re include std/pretty.e include std/sequence.e puts(1, "Content-type: text/text\r\n\r\n") object nbytes, data nbytes = getenv("CONTENT_LENGTH") if atom(nbytes) then puts(1, "failure") abort(0) end if nbytes = value(nbytes) nbytes = nbytes[2] if sequence(nbytes) or nbytes < 1 then puts(1, "failed") abort(0) end if data = get_bytes(0,nbytes) object r = re:new("(.+?)\r\nContent-Disposition: (.+?); name=\"(.+?)\"; filename=\"([^\"]+?)\"\r\nContent-Type: (.+?)\r\n") object matches = re:all_matches(r , data) integer fn = open(matches[5], "w") if fn = -1 then puts(1, "fail") abort(0) end if puts(fn, slice(data, length(matches[1])+1)) close(fn) puts(1, "success")
bugmagnet