예제 #1
0
def action_crawler():
    config_path = os.path.join(app.root_path, 'controller/ueditor/config.json')
    fp = open(config_path, 'r')
    config = json.load(fp)
    fp.close()

    config = {
        "pathFormat": config['catcherPathFormat'],
        "maxSize": config['catcherMaxSize'],
        "allowFiles": config['catcherAllowFiles'],
        "oriName": "remote.png"
    }
    fieldName = config['catcherFieldName']

    list = []
    source = request.form[fieldName] if request.form.has_key(fieldName) else request.args.get(fieldName, None)

    for imgUrl in source:
        from uploader import Uploader
        item = Uploader(imgUrl, config, "remote")
        info = item.getFileInfo()
        list.append({
            "state": info["state"],
            "url": info["url"],
            "size": info["size"],
            "title": cgi.escape(info["title"]),
            "original": cgi.escape(info["original"]),
            "source": cgi.escape(imgUrl)
        })

    return jsonify({
        'state': 'SUCCESS' if len(list) else 'ERROR',
        'list': list
    })
예제 #2
0
파일: views.py 프로젝트: hugesoft/flaskCMS
def upload():
    """UEditor文件上传接口

    config 配置文件
    result 返回结果
    """
    mimetype = 'application/json'
    result = {}
       
    action = request.args.get('action')

    # 解析JSON格式的配置文件
    with open(os.path.join(app.static_folder,'ueditor','php','config.json')) as fp:
        try:
            # 删除 `/**/` 之间的注释
            CONFIG = json.loads(re.sub(r'\/\*.*\*\/', '', fp.read()))
        except:
            CONFIG = {}
                
    if action == 'config':
        # 初始化时,返回配置文件给客户端
        result = CONFIG

    elif action in ('uploadimage', 'uploadfile', 'uploadvideo'):
        # 图片、文件、视频上传
        if action == 'uploadimage':
            fieldName = CONFIG.get('imageFieldName')
            config = {
                "pathFormat": CONFIG['imagePathFormat'],
                "maxSize": CONFIG['imageMaxSize'],
                "allowFiles": CONFIG['imageAllowFiles']
            }
        elif action == 'uploadvideo':
            fieldName = CONFIG.get('videoFieldName')
            config = {
                "pathFormat": CONFIG['videoPathFormat'],
                "maxSize": CONFIG['videoMaxSize'],
                "allowFiles": CONFIG['videoAllowFiles']
            }
        else:
            fieldName = CONFIG.get('fileFieldName')
            config = {
                "pathFormat": CONFIG['filePathFormat'],
                "maxSize": CONFIG['fileMaxSize'],
                "allowFiles": CONFIG['fileAllowFiles']
            }

        if fieldName in request.files:
            field = request.files[fieldName]
            uploader = Uploader(field, config, app.static_folder)
            result = uploader.getFileInfo()
        else:
            result['state'] = '上传接口出错'

    elif action in ('uploadscrawl'):
        # 涂鸦上传
        fieldName = CONFIG.get('scrawlFieldName')
        config = {
            "pathFormat": CONFIG.get('scrawlPathFormat'),
            "maxSize": CONFIG.get('scrawlMaxSize'),
            "allowFiles": CONFIG.get('scrawlAllowFiles'),
            "oriName": "scrawl.png"
        }
        if fieldName in request.form:
            field = request.form[fieldName]
            uploader = Uploader(field, config, app.static_folder, 'base64')
            result = uploader.getFileInfo()
        else:
            result['state'] = '上传接口出错'

    elif action in ('catchimage'):
        config = {
            "pathFormat": CONFIG['catcherPathFormat'],
            "maxSize": CONFIG['catcherMaxSize'],
            "allowFiles": CONFIG['catcherAllowFiles'],
            "oriName": "remote.png"
        }
        fieldName = CONFIG['catcherFieldName']

        if fieldName in request.form:
            # 这里比较奇怪,远程抓图提交的表单名称不是这个
            source = []
        elif '%s[]' % fieldName in request.form:
            # 而是这个
            source = request.form.getlist('%s[]' % fieldName)

        _list = []
        for imgurl in source:
            uploader = Uploader(imgurl, config, app.static_folder, 'remote')
            info = uploader.getFileInfo()
            _list.append({
                'state': info['state'],
                'url': info['url'],
                'original': info['original'],
                'source': imgurl,
            })

        result['state'] = 'SUCCESS' if len(_list) > 0 else 'ERROR'
        result['list'] = _list

    else:
        result['state'] = '请求地址出错'

    result = json.dumps(result)

    if 'callback' in request.args:
        callback = request.args.get('callback')
        if re.match(r'^[\w_]+$', callback):
            result = '%s(%s)' % (callback, result)
            mimetype = 'application/javascript'
        else:
            result = json.dumps({'state': 'callback参数不合法'})

    res = make_response(result)
    res.mimetype = mimetype
    res.headers['Access-Control-Allow-Origin'] = '*'
    res.headers['Access-Control-Allow-Headers'] = 'X-Requested-With,X_Requested_With'
    return res
예제 #3
0
def upload():
    """UEditor文件上传接口

    config 配置文件
    result 返回结果
    """
    mimetype = 'application/json'
    result = {}
    action = request.args.get('action')

    # 解析JSON格式的配置文件
    with open(os.path.join(app.static_folder, 'ueditor', 'php',
                           'config.json')) as fp:
        try:
            # 删除 `/**/` 之间的注释
            CONFIG = json.loads(re.sub(r'\/\*.*\*\/', '', fp.read()))
        except:
            CONFIG = {}

    if action == 'config':
        # 初始化时,返回配置文件给客户端
        result = CONFIG

    elif action in ('uploadimage', 'uploadfile', 'uploadvideo'):
        # 图片、文件、视频上传
        if action == 'uploadimage':
            fieldName = CONFIG.get('imageFieldName')
            config = {
                "pathFormat": CONFIG['imagePathFormat'],
                "maxSize": CONFIG['imageMaxSize'],
                "allowFiles": CONFIG['imageAllowFiles']
            }
        elif action == 'uploadvideo':
            fieldName = CONFIG.get('videoFieldName')
            config = {
                "pathFormat": CONFIG['videoPathFormat'],
                "maxSize": CONFIG['videoMaxSize'],
                "allowFiles": CONFIG['videoAllowFiles']
            }
        else:
            fieldName = CONFIG.get('fileFieldName')
            config = {
                "pathFormat": CONFIG['filePathFormat'],
                "maxSize": CONFIG['fileMaxSize'],
                "allowFiles": CONFIG['fileAllowFiles']
            }

        if fieldName in request.files:
            field = request.files[fieldName]
            uploader = Uploader(field, config, app.static_folder)
            result = uploader.getFileInfo()
        else:
            result['state'] = '上传接口出错'

    elif action in ('uploadscrawl'):
        # 涂鸦上传
        fieldName = CONFIG.get('scrawlFieldName')
        config = {
            "pathFormat": CONFIG.get('scrawlPathFormat'),
            "maxSize": CONFIG.get('scrawlMaxSize'),
            "allowFiles": CONFIG.get('scrawlAllowFiles'),
            "oriName": "scrawl.png"
        }
        if fieldName in request.form:
            field = request.form[fieldName]
            uploader = Uploader(field, config, app.static_folder, 'base64')
            result = uploader.getFileInfo()
        else:
            result['state'] = '上传接口出错'

    elif action in ('catchimage'):
        config = {
            "pathFormat": CONFIG['catcherPathFormat'],
            "maxSize": CONFIG['catcherMaxSize'],
            "allowFiles": CONFIG['catcherAllowFiles'],
            "oriName": "remote.png"
        }
        fieldName = CONFIG['catcherFieldName']

        if fieldName in request.form:
            # 这里比较奇怪,远程抓图提交的表单名称不是这个
            source = []
        elif '%s[]' % fieldName in request.form:
            # 而是这个
            source = request.form.getlist('%s[]' % fieldName)

        _list = []
        for imgurl in source:
            uploader = Uploader(imgurl, config, app.static_folder, 'remote')
            info = uploader.getFileInfo()
            _list.append({
                'state': info['state'],
                'url': info['url'],
                'original': info['original'],
                'source': imgurl,
            })

        result['state'] = 'SUCCESS' if len(_list) > 0 else 'ERROR'
        result['list'] = _list

    else:
        result['state'] = '请求地址出错'

    result = json.dumps(result)

    if 'callback' in request.args:
        callback = request.args.get('callback')
        if re.match(r'^[\w_]+$', callback):
            result = '%s(%s)' % (callback, result)
            mimetype = 'application/javascript'
        else:
            result = json.dumps({'state': 'callback参数不合法'})

    res = make_response(result)
    res.mimetype = mimetype
    res.headers['Access-Control-Allow-Origin'] = '*'
    res.headers[
        'Access-Control-Allow-Headers'] = 'X-Requested-With,X_Requested_With'
    return res
예제 #4
0
파일: blog.py 프로젝트: jannson/app
    def post(self):
        CONFIG = {}
        result = {}
        mimetype = 'application/json'
        action = self.get_argument("action", default=None)
        request = self.request

        with open(os.path.join(STATIC_PATH,"ueditor","php","config.json")) as fp:
            CONFIG = json.loads(re.sub(r'\/\*.*\*\/', '', fp.read()))

        if action == "config":
            result = CONFIG
        elif action in ('uploadimage', 'uploadfile', 'uploadvideo'):
            if action == 'uploadimage':
                fieldName = CONFIG.get('imageFieldName')
                config = {
                    "pathFormat": CONFIG['imagePathFormat'],
                    "maxSize": CONFIG['imageMaxSize'],
                    "allowFiles": CONFIG['imageAllowFiles']
                }
            elif action == 'uploadvideo':
                fieldName = CONFIG.get('videoFieldName')
                config = {
                    "pathFormat": CONFIG['videoPathFormat'],
                    "maxSize": CONFIG['videoMaxSize'],
                    "allowFiles": CONFIG['videoAllowFiles']
                }
            else:
                fieldName = CONFIG.get('fileFieldName')
                config = {
                    "pathFormat": CONFIG['filePathFormat'],
                    "maxSize": CONFIG['fileMaxSize'],
                    "allowFiles": CONFIG['fileAllowFiles']
                }

            if fieldName in request.files:
                field = request.files[fieldName][0]
                uploader = Uploader(WrapFileObj(field), config, UPLOAD_PATH)
                result = uploader.getFileInfo()
            else:
                result['state'] = u'上传接口出错'

        elif action in ('uploadscrawl'):
            # 涂鸦上传
            fieldName = CONFIG.get('scrawlFieldName')
            config = {
                "pathFormat": CONFIG.get('scrawlPathFormat'),
                "maxSize": CONFIG.get('scrawlMaxSize'),
                "allowFiles": CONFIG.get('scrawlAllowFiles'),
                "oriName": "scrawl.png"
            }
            if fieldName in request.form:
                field = request.form[fieldName][0]
                uploader = Uploader(WrapFileObj(field), config, UPLOAD_PATH, 'base64')
                result = uploader.getFileInfo()
            else:
                result['state'] = u'上传接口出错'

        elif action in ('catchimage'):
            config = {
                "pathFormat": CONFIG['catcherPathFormat'],
                "maxSize": CONFIG['catcherMaxSize'],
                "allowFiles": CONFIG['catcherAllowFiles'],
                "oriName": "remote.png"
            }
            fieldName = CONFIG['catcherFieldName']
            if fieldName in request.form:
                # 这里比较奇怪,远程抓图提交的表单名称不是这个
                source = []
            elif '%s[]' % fieldName in request.form:
                # 而是这个
                source = request.form.getlist('%s[]' % fieldName)
            _list = []
            for imgurl in source:
                uploader = Uploader(imgurl, config, UPLOAD_PATH, 'remote')
                info = uploader.getFileInfo()
                _list.append({
                    'state': info['state'],
                    'url': info['url'],
                    'original': info['original'],
                    'source': imgurl,
                })
            result['state'] = 'SUCCESS' if len(_list) > 0 else 'ERROR'
            result['list'] = _list
        else:
            result['state'] = u'请求地址出错'

        callback = self.get_argument('callback', None)
        if callback:
            if re.match(r'^[\w_]+$', callback):
                result = '%s(%s)' % (callback, result)
                mimetype = 'application/javascript'
            else:
                result = json.dumps({'state': u'callback参数不合法'})

        self.set_header("Content-Type", "application/json")
        self.set_header("Access-Control-Allow-Origin", "*")
        self.set_header("Access-Control-Allow-Headers", "*")
        result = json.dumps(result)
        self.write(result)
예제 #5
0
    def post(self):
        CONFIG = {}
        result = {}
        mimetype = 'application/json'
        action = self.get_argument("action", default=None)
        request = self.request

        with open(os.path.join(STATIC_PATH, "ueditor", "php",
                               "config.json")) as fp:
            CONFIG = json.loads(re.sub(r'\/\*.*\*\/', '', fp.read()))

        if action == "config":
            result = CONFIG
        elif action in ('uploadimage', 'uploadfile', 'uploadvideo'):
            if action == 'uploadimage':
                fieldName = CONFIG.get('imageFieldName')
                config = {
                    "pathFormat": CONFIG['imagePathFormat'],
                    "maxSize": CONFIG['imageMaxSize'],
                    "allowFiles": CONFIG['imageAllowFiles']
                }
            elif action == 'uploadvideo':
                fieldName = CONFIG.get('videoFieldName')
                config = {
                    "pathFormat": CONFIG['videoPathFormat'],
                    "maxSize": CONFIG['videoMaxSize'],
                    "allowFiles": CONFIG['videoAllowFiles']
                }
            else:
                fieldName = CONFIG.get('fileFieldName')
                config = {
                    "pathFormat": CONFIG['filePathFormat'],
                    "maxSize": CONFIG['fileMaxSize'],
                    "allowFiles": CONFIG['fileAllowFiles']
                }

            if fieldName in request.files:
                field = request.files[fieldName][0]
                uploader = Uploader(WrapFileObj(field), config, UPLOAD_PATH)
                result = uploader.getFileInfo()
            else:
                result['state'] = u'上传接口出错'

        elif action in ('uploadscrawl'):
            # 涂鸦上传
            fieldName = CONFIG.get('scrawlFieldName')
            config = {
                "pathFormat": CONFIG.get('scrawlPathFormat'),
                "maxSize": CONFIG.get('scrawlMaxSize'),
                "allowFiles": CONFIG.get('scrawlAllowFiles'),
                "oriName": "scrawl.png"
            }
            if fieldName in request.form:
                field = request.form[fieldName][0]
                uploader = Uploader(WrapFileObj(field), config, UPLOAD_PATH,
                                    'base64')
                result = uploader.getFileInfo()
            else:
                result['state'] = u'上传接口出错'

        elif action in ('catchimage'):
            config = {
                "pathFormat": CONFIG['catcherPathFormat'],
                "maxSize": CONFIG['catcherMaxSize'],
                "allowFiles": CONFIG['catcherAllowFiles'],
                "oriName": "remote.png"
            }
            fieldName = CONFIG['catcherFieldName']
            if fieldName in request.form:
                # 这里比较奇怪,远程抓图提交的表单名称不是这个
                source = []
            elif '%s[]' % fieldName in request.form:
                # 而是这个
                source = request.form.getlist('%s[]' % fieldName)
            _list = []
            for imgurl in source:
                uploader = Uploader(imgurl, config, UPLOAD_PATH, 'remote')
                info = uploader.getFileInfo()
                _list.append({
                    'state': info['state'],
                    'url': info['url'],
                    'original': info['original'],
                    'source': imgurl,
                })
            result['state'] = 'SUCCESS' if len(_list) > 0 else 'ERROR'
            result['list'] = _list
        else:
            result['state'] = u'请求地址出错'

        callback = self.get_argument('callback', None)
        if callback:
            if re.match(r'^[\w_]+$', callback):
                result = '%s(%s)' % (callback, result)
                mimetype = 'application/javascript'
            else:
                result = json.dumps({'state': u'callback参数不合法'})

        self.set_header("Content-Type", "application/json")
        self.set_header("Access-Control-Allow-Origin", "*")
        self.set_header("Access-Control-Allow-Headers", "*")
        result = json.dumps(result)
        self.write(result)
예제 #6
0
파일: mine.py 프로젝트: hejinwei/xm_diary
         config = {
             "pathFormat": CONFIG['videoPathFormat'],
             "maxSize": CONFIG['videoMaxSize'],
             "allowFiles": CONFIG['videoAllowFiles']
         }
     else:
         fieldName = CONFIG.get('fileFieldName')
         config = {
             "pathFormat": CONFIG['filePathFormat'],
             "maxSize": CONFIG['fileMaxSize'],
             "allowFiles": CONFIG['fileAllowFiles']
         }
     if fieldName in request.files:
         field = request.files[fieldName]
         uploader = Uploader(field, config, static_home)
         result = uploader.getFileInfo()
     else:
         result['state'] = '上传接口出错'
 elif action in ('uploadscrawl'):
     # 涂鸦上传
     fieldName = CONFIG.get('scrawlFieldName')
     config = {
         "pathFormat": CONFIG.get('scrawlPathFormat'),
         "maxSize": CONFIG.get('scrawlMaxSize'),
         "allowFiles": CONFIG.get('scrawlAllowFiles'),
         "oriName": "scrawl.png"
     }
     if fieldName in request.form:
         field = request.form[fieldName]
         uploader = Uploader(field, config, static_home, 'base64')
         result = uploader.getFileInfo()
예제 #7
0
파일: views.py 프로젝트: hugesoft/flask-7_2
def upload():
    """UEditor文件上传接口

    config 配置文件
    result 返回结果
    """
    mimetype = "application/json"
    result = {}
    action = request.args.get("action")

    # 解析JSON格式的配置文件
    with open(os.path.join(app.static_folder, "ueditor", "php", "config.json")) as fp:
        try:
            # 删除 `/**/` 之间的注释
            CONFIG = json.loads(re.sub(r"\/\*.*\*\/", "", fp.read()))
        except:
            CONFIG = {}

    if action == "config":
        # 初始化时,返回配置文件给客户端
        result = CONFIG

    elif action in ("uploadimage", "uploadfile", "uploadvideo"):
        # 图片、文件、视频上传
        if action == "uploadimage":
            fieldName = CONFIG.get("imageFieldName")
            config = {
                "pathFormat": CONFIG["imagePathFormat"],
                "maxSize": CONFIG["imageMaxSize"],
                "allowFiles": CONFIG["imageAllowFiles"],
            }
        elif action == "uploadvideo":
            fieldName = CONFIG.get("videoFieldName")
            config = {
                "pathFormat": CONFIG["videoPathFormat"],
                "maxSize": CONFIG["videoMaxSize"],
                "allowFiles": CONFIG["videoAllowFiles"],
            }
        else:
            fieldName = CONFIG.get("fileFieldName")
            config = {
                "pathFormat": CONFIG["filePathFormat"],
                "maxSize": CONFIG["fileMaxSize"],
                "allowFiles": CONFIG["fileAllowFiles"],
            }

        if fieldName in request.files:
            field = request.files[fieldName]
            uploader = Uploader(field, config, editor.static_folder)
            result = uploader.getFileInfo()
        else:
            result["state"] = "上传接口出错"

    elif action in ("uploadscrawl"):
        # 涂鸦上传
        fieldName = CONFIG.get("scrawlFieldName")
        config = {
            "pathFormat": CONFIG.get("scrawlPathFormat"),
            "maxSize": CONFIG.get("scrawlMaxSize"),
            "allowFiles": CONFIG.get("scrawlAllowFiles"),
            "oriName": "scrawl.png",
        }
        if fieldName in request.form:
            field = request.form[fieldName]
            uploader = Uploader(field, config, editor.static_folder, "base64")
            result = uploader.getFileInfo()
        else:
            result["state"] = "上传接口出错"

    elif action in ("catchimage"):
        config = {
            "pathFormat": CONFIG["catcherPathFormat"],
            "maxSize": CONFIG["catcherMaxSize"],
            "allowFiles": CONFIG["catcherAllowFiles"],
            "oriName": "remote.png",
        }
        fieldName = CONFIG["catcherFieldName"]

        if fieldName in request.form:
            # 这里比较奇怪,远程抓图提交的表单名称不是这个
            source = []
        elif "%s[]" % fieldName in request.form:
            # 而是这个
            source = request.form.getlist("%s[]" % fieldName)

        _list = []
        for imgurl in source:
            uploader = Uploader(imgurl, config, editor.static_folder, "remote")
            info = uploader.getFileInfo()
            _list.append({"state": info["state"], "url": info["url"], "original": info["original"], "source": imgurl})

        result["state"] = "SUCCESS" if len(_list) > 0 else "ERROR"
        result["list"] = _list

    else:
        result["state"] = "请求地址出错"

    result = json.dumps(result)

    if "callback" in request.args:
        callback = request.args.get("callback")
        if re.match(r"^[\w_]+$", callback):
            result = "%s(%s)" % (callback, result)
            mimetype = "application/javascript"
        else:
            result = json.dumps({"state": "callback参数不合法"})

    res = make_response(result)
    res.mimetype = mimetype
    res.headers["Access-Control-Allow-Origin"] = "*"
    res.headers["Access-Control-Allow-Headers"] = "X-Requested-With,X_Requested_With"
    return res
예제 #8
0
def action_upload():
    base64 = "upload"
    config_path = os.path.join(app.root_path, 'controller/ueditor/config.json')
    fp = open(config_path, 'r')
    config = json.load(fp)
    fp.close()
    action = request.args.get('action', None)
    if action == 'uploadimage':
        print '====================='
        config.update({
            "pathFormat": config['imagePathFormat'],
            "maxSize": config['imageMaxSize'],
            "allowFiles": config['imageAllowFiles']
        })
        fieldname = config['imageFieldName']

    elif action == 'uploadscrawl':
        config = {
            "pathFormat": config['scrawlPathFormat'],
            "maxSize": config['scrawlMaxSize'],
            "allowFiles": config['scrawlAllowFiles'],
            "oriName": "scrawl.png"
        }
        fieldname = config['scrawlFieldName']
        base64 = "base64"

    elif action == 'uploadvideo':
        config = {
            "pathFormat": config['videoPathFormat'],
            "maxSize": config['videoMaxSize'],
            "allowFiles": config['videoAllowFiles']
        }
        fieldname = config['videoFieldName']

    else:
    #elif action == 'uploadfile':
        config.update({
            "pathFormat": config['filePathFormat'],
            "maxSize": config['fileMaxSize'],
            "allowFiles": config['fileAllowFiles']
        })
        print config
        fieldname = config['fileFieldName']

    #print config,'==========='
    from uploader import Uploader
    up = Uploader(fieldname, config, base64)
    '''
    /**
     * 得到上传文件所对应的各个参数,数组结构
     * array(
     *     "state" => "",          //上传状态,上传成功时必须返回"SUCCESS"
     *     "url" => "",            //返回的地址
     *     "title" => "",          //新文件名
     *     "original" => "",       //原始文件名
     *     "type" => ""            //文件类型
     *     "size" => "",           //文件大小
     * )
     */

    /* 返回数据 */'''
    return jsonify(up.getFileInfo())
예제 #9
0
파일: main.py 프로젝트: nixiaocang/upload
    def upload(self, *args, **kwargs):
        mimetype = 'application/json'
        result = {}
        action = self.get_argument('action')
        path = '/Users/jiaoguofu/Downloads/ueditor-1.4.3.3/dist/utf8-php/php/config.json'
        with open(path) as fp:
            try:
                CONFIG = json.loads(re.sub(r'\/\*.*\*\/', '', fp.read()))
            except:
                CONFIG = {}
        if action == 'config':
            result = CONFIG
        elif action in ('uploadimage', 'uploadfile', 'uploadvideo'):
            if action == 'uploadimage':
                fieldName = CONFIG.get('imageFieldName')
                config = {
                    "pathFormat": CONFIG['imagePathFormat'],
                    "maxSize": CONFIG['imageMaxSize'],
                    "allowFiles": CONFIG['imageAllowFiles']
                }
            elif action == 'uploadvideo':
                fieldName = CONFIG.get('videoFieldName')
                config = {
                    "pathFormat": CONFIG['videoPathFormat'],
                    "maxSize": CONFIG['videoMaxSize'],
                    "allowFiles": CONFIG['videoAllowFiles']
                }
            else:
                fieldName = CONFIG.get('fileFieldName')
                config = {
                    "pathFormat": CONFIG['filePathFormat'],
                    "maxSize": CONFIG['fileMaxSize'],
                    "allowFiles": CONFIG['fileAllowFiles']
                }

            if fieldName in self.request.files:
                field = self.request.files[fieldName]
                for fieldsss in field:
                    uploader = Uploader(fieldsss, config, static_path)
                    result = uploader.getFileInfo()
                    break
            else:
                result['state'] = '上传接口出错'

        elif action in ('uploadscrawl'):
            # 涂鸦上传
            fieldName = CONFIG.get('scrawlFieldName')
            config = {
                "pathFormat": CONFIG.get('scrawlPathFormat'),
                "maxSize": CONFIG.get('scrawlMaxSize'),
                "allowFiles": CONFIG.get('scrawlAllowFiles'),
                "oriName": "scrawl.png"
            }
            if fieldName in self.request.form:
                field = self.request.form[fieldName]
                uploader = Uploader(field, config, static_path, 'base64')
                result = uploader.getFileInfo()
            else:
                result['state'] = '上传接口出错'

        elif action in ('catchimage'):
            config = {
                "pathFormat": CONFIG['catcherPathFormat'],
                "maxSize": CONFIG['catcherMaxSize'],
                "allowFiles": CONFIG['catcherAllowFiles'],
                "oriName": "remote.png"
            }
            fieldName = CONFIG['catcherFieldName']

            if fieldName in self.request.form:
                # 这里比较奇怪,远程抓图提交的表单名称不是这个
                source = []
            elif '%s[]' % fieldName in self.request.form:
                # 而是这个
                source = self.request.form.getlist('%s[]' % fieldName)

            _list = []
            for imgurl in source:
                uploader = Uploader(imgurl, config, static_path, 'remote')
                info = uploader.getFileInfo()
                _list.append({
                    'state': info['state'],
                    'url': info['url'],
                    'original': info['original'],
                    'source': imgurl,
                })

            result['state'] = 'SUCCESS' if len(_list) > 0 else 'ERROR'
            result['list'] = _list

        else:
            result['state'] = '请求地址出错'

        result = json.dumps(result)

        if self.request.arguments.has_key("callback"):
            callback = self.get_argument('callback')
            if re.match(r'^[\w_]+$', callback):
                result = '%s(%s)' % (callback, result)
                mimetype = 'application/javascript'
            else:
                result = json.dumps({'state': 'callback参数不合法'})

        self.set_header('Content-Type', mimetype)
        self.set_header('Access-Control-Allow-Origin', '*')
        self.set_header('Access-Control-Allow-Headers',
                        'X-Requested-With,X_Requested_With')
        self.write(result)
        self.finish()