Re: Receiving a POSTed file

new topic     » goto parent     » topic index » view thread      » older message » newer message
include std/regex.e as re 
include std/pretty.e 
 
object r = re:new("(.+?)\r\nContent-Disposition: (.+?); name=\"(.+?)\"; filename=\"([^\"]+?)\"\r\nContent-Type: (.+?)\r\n") 
object matches = re:all_matches(r , "------WebKitFormBoundarylHdLZsq10IBUKBPg\r\n" &  
"Content-Disposition: form-data; name=\"file\"; filename=\"Jen.docx\"\r\n" & 
"Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document\r\n") 
pretty_print( 1, matches, {2}) 

Ok, that wasn't too hard. Was a bit taken aback by the absence of some regular expression syntax (like \S) but the above works and gives

{ 
  { 
    "------WebKitFormBoundarylHdLZsq10IBUKBPg\r\nContent-Disposition: form-data; name=\"file\"; filename=\"Jen.docx\"\r\nContent-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document\r\n", 
    "------WebKitFormBoundarylHdLZsq10IBUKBPg", 
    "form-data", 
    "file", 
    "Jen.docx", 
    "application/vnd.openxmlformats-officedocument.wordprocessingml.document" 
  } 
} 

So I can recover the filename and content-type, and then remove the matched header from the data which was what I was after.

Am about to find out how big a file I upload with this.

Thanks again,
bugmagnet

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu