Python - Parsing multipart/form-data request on server side

前端 未结 3 1314
北恋
北恋 2021-01-12 09:00

Im trying to do a http \'POST\' with multipart/form-data to a python GAE backend. My server side method is receiving the complete body but i have absolutely no idea how to p

相关标签:
3条回答
  • 2021-01-12 09:14

    You want the .cgi python library.

    Specifically something like this:

    import cgi
    form = cgi.FieldStorage() 
    value1 = form.getfirst("value1", "")
    value2 = form.getfirst("value2", "") 
    value3 = form.getfirst("value3", "") 
    logtext = form.getfirst("logText", "")
    
    0 讨论(0)
  • 2021-01-12 09:28

    If you want the uploaded files, you can do this

    for upload in self.get_uploads():

    If you want just a text field:

    x = self.request.get('value1')

    0 讨论(0)
  • 2021-01-12 09:31

    For some reason cgi.FieldStorage() wasnt working for me, but only the deprecated method :

    pdict = {'boundary':'*****'}
    cgi.parse_multipart(self.request.body_file, pdict)
    

    Dont know why but as long as its working im fine with that.

    0 讨论(0)
提交回复
热议问题