webuploader+python3(BaseHTTPRequestHandler)实现图片文件的上传与接收存储

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/iceboy314159/article/details/53227799

前端代码及详细讲解见以下链接:

http://fex.baidu.com/webuploader/getting-started.html

python3后台部分处理代码如下:

from cgi import parse_header, parse_multipart
import cgi
#import other ...
class BeiDouHTTPRequestHandler(BaseHTTPRequestHandler):
    def do_OPTIONS(self):
    #...
    def do_GET(self):
    #...  

    def do_POST(self):
        self.send_response(200)
        self.send_header("Access-Control-Allow-Origin", "*")
        self.end_headers()
        parsed_path = parse.urlparse(self.path)
        arr_str = self.path.split('/')
		
		# save received images to the path ./images/filename
        if arr_str[1] == 'imgdeal':
            form = cgi.FieldStorage(
                fp=self.rfile,
                headers=self.headers,
                environ={'REQUEST_METHOD': 'POST',
                         'CONTENT_TYPE': self.headers['Content-Type'],
                         }
            )
            path = 'images//'+form.getvalue('name')
            f = open(path,'wb')
            f.write(form.getvalue('file'))
            f.close()
		# elif process



展开阅读全文

没有更多推荐了,返回首页