Let me start by saying, I am using the twisted.web framework. File uploading of twisted.web does not work as I wanted it (contains only file data, and no other information), cgi.parse_multipart does not work Like I want to do it (same thing, twisted.web uses this function), cgi.FieldStorage did not work (because I'm getting post data Through twisted, there is no CGI interface - as far as I can tell, Field Store I try to get the request through stdin), and twisted.web2 does not work for me because used was confused and bothered by me ( Which I want to do) is very complex.
It is being said, I tried and just decided to parse the HTTP request.
Using Chrome, the HTTP request is made in such a way:
------ WebKit FrameBoundary 7fouZ8mEjlCe92pq Content Disposition: Form-Data; Name = "upload_file_onepace" 11b03b61-9252-11df-a357-00266c608adb ------ webkitformboundary7fouZ8mEjlCe92pq content-presentation: form-data; Name = "file"; Filename = "login.html" content-type: text / html & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; ... ------ WebKitFormBoundary7fouZ8mEjlCe92pq Content-presentation: Form-data; Name = "file"; Filename = "" ------ WebKitFormBoundary7fouZ8mEjlCe92pq-- Is it always that how will it become? I'm parsing it with regular expressions, like (sorry for the code's wall):
(Note, the only thing I just thought was to remove the code for showing only relevant (regular Expressions (yes, nested brackets), this I have created in a upload class in a __init __ method (the only method so far). Can be seen (I hope that I have any brackets I do not match)
if line == "- {0} -". Format (range): expired = true if in_header == is correct and not line: In_header = False 'Not in current_file' type: ignore_current_file = true if in_header == is true: m = re.match ("content-presentation: form-data; name = \" (. *?) \ "; Filename = \" (. *?) \ "$", Line) if m: input_name, current_file ['file name'] = mgpr. (1), mgp (2) m = re match. ("Content -Type: (. *) $ ', Line) If m: current_file [' type '] = mgp (1) other: if' day Is not in the current_file: current_file ['data'] = line other: current_file ['data'] + = line You can see that when a limit is exceeded I start a new "file" word. I want to set the in_header to true that I am parsing the header when I reach a blank line, then I get it to be incorrect - but not before checking that if any content-type was set for that form value - if not, then I set ignore_current_file Because I'm only looking for file uploads
I know that I have a book The rhythm should be used, but I am trying to get different solutions to work in my project, death of reading documentation, and still looking at the code appropriate. I just want to finish this part - and if it is easy to parse an HTTP POST with file uploads, then I will be with him.
Note: This code works perfectly for now, I'm just wondering if it will mess some of the browsers / spit.
You are trying to avoid reading documentation, but I think the best advice really is Read:
- RFC 2388
- RFC 1867
To ensure that you do not miss any case There is an easy way to use the I library.
Comments
Post a Comment