Esempio n. 1
0
def upload_file(filename, path):
    """ 上传文件
    - `path`      文件路径
    """
    form = Form()
    filename = filename.encode("utf-8")
    form.add_file(fieldname='img', filename=filename, fileHandle=open(path))
    img_host = "http://paste.linuxzen.com"
    #img_host = "http://localhost:8800"
    req = urllib2.Request(img_host)
    req.add_header("Content-Type", form.get_content_type())
    req.add_header("Content-Length", len(str(form)))
    req.add_data(str(form))
    return urllib2.urlopen(req)
Esempio n. 2
0
def upload_file(filename, path):
    """ 上传文件
    - `path`      文件路径
    """
    form = Form()
    filename = filename.encode("utf-8")
    form.add_file(fieldname='img', filename=filename,
                    fileHandle=open(path))
    img_host = "http://paste.linuxzen.com"
    #img_host = "http://localhost:8800"
    req = urllib2.Request(img_host)
    req.add_header("Content-Type", form.get_content_type())
    req.add_header("Content-Length", len(str(form)))
    req.add_data(str(form))
    return urllib2.urlopen(req)
Esempio n. 3
0
File: hub.py Progetto: udbmnm/twqq
    def upload_file(self, filename, path):
        """ 上传文件

        :param filename: 文件名
        :param path: 文件路径
        """
        form = Form()
        filename = filename.encode("utf-8")
        form.add_file(fieldname="name", filename=filename, fileHandle=open(path))
        img_host = "http://dimg.vim-cn.com/"
        req = urllib2.Request(img_host)
        req.add_header("Content-Type", form.get_content_type())
        req.add_header("Content-Length", len(str(form)))
        req.add_header("User-Agent", "curl/python")
        req.add_data(str(form))
        return urllib2.urlopen(req)
Esempio n. 4
0
def upload_file(filename, path):
    """ 上传文件
    - `path`      文件路径
    """
    form = Form()
    filename = filename.encode("utf-8")
    form.add_file(fieldname='name', filename=filename,
                    fileHandle=open(path))
    img_host = "http://img.vim-cn.com/"
    #img_host = "http://localhost:8800"
    req = urllib2.Request(img_host)
    req.add_header("Content-Type", form.get_content_type())
    req.add_header("Content-Length", len(str(form)))
    req.add_header("User-Agent", "curl/python")
    req.add_data(str(form))
    return urllib2.urlopen(req)
Esempio n. 5
0
    def upload_file(self, filename, path):
        """ 上传文件

        :param filename: 文件名
        :param path: 文件路径
        """
        form = Form()
        filename = filename.encode("utf-8")
        form.add_file(fieldname='name', filename=filename,
                        fileHandle=open(path))
        img_host = "http://dimg.vim-cn.com/"
        req = urllib2.Request(img_host)
        req.add_header("Content-Type", form.get_content_type())
        req.add_header("Content-Length", len(str(form)))
        req.add_header("User-Agent", "curl/python")
        req.add_data(str(form))
        return urllib2.urlopen(req)