Web. py multipart File Handling

Source: Internet
Author: User
Tags file handling

I'll have to admit that... it was so easy to use $ _ file for file uploading in PHP.

Trying to switch to python from PhP (for varous reasons including shared Configuration between web and background processes, etc ). started looking at web. PY (with other alternatives as well) and, surprisingly, found that the webpy's document is nothing
More than... Nothing. Even the "receipts" in "cookbook" are for those who don't need them. So I'm lost totally just in handling uploaded file.

Task: to handle a file upload.

Solution:

 
Def post (Self): x = web. Input ('log', log = {})

Trick here is the log = {} Part. without it, X. log wocould be a string containing the whole content of the file. this is a completely uninitialized ented behavior. if you need something more familiar, specify the "log = {}" part, and you'll get X. log. filename
For remote filename and X. log. file for a file object to access it. I still haven'tfigured out how to directly operate on the uploaded file (or Python didn't do this part at all ?) But at least I got a file object to deal.

Related code:

Https://github.com/webpy/webpy/blob/master/web/utils.py#L160

If the key is not in the "defaults", or the specified defaults value isn't a dict, value is inflated before added to the storage object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.