def uploadImage(): resp = {'state': 'SUCCESS', 'url': '', 'title': '', 'original': ''} file_target = request.files upfile = file_target['upfile'] if 'upfile' in file_target else None if upfile is None: resp['state'] = '上传失败' return jsonify(resp) ret = UploadService.uploadFile(upfile) if ret['code'] != 200: resp['state'] = '上传失败:' + ret['msg'] return jsonify(resp) resp['url'] = UrlManager.buildImageUrl(ret['data']['file_key']) return jsonify(resp)
def uploadPic(): file_target = request.files upfile = file_target['pic'] if 'pic' in file_target else None callback_target = 'window.parent.upload' if upfile is None: return "<script type='text/javascript'>{0}.error('{1}')</script>".format( callback_target, "上传失败") ret = UploadService.uploadFile(upfile) if ret['code'] != 200: return "<script type='text/javascript'>{0}.error('{1}')</script>".format( callback_target, "上传失败:" + ret['msg']) return "<script type='text/javascript'>{0}.success('{1}')</script>".format( callback_target, ret['data']['file_key'])