def blob(id): resource = ResourceDomain().get(id) file = mongolib.get(resource.blob_id) return send_file(io.BytesIO(file.read()), mimetype=file.content_type, as_attachment=True, attachment_filename=resource.filename, cache_timeout=0)
def upload(): files = {} for (k, f) in request.files.items(): files[f.filename.strip('"')] = f arg = { 'title': request.values.get('title', default=''), 'tags': request.values.get('tags', default='') } result = ResourceDomain().create(files, **arg) return jsonify(result)
def img(id): parser = reqparse.RequestParser() parser.add_argument('format', type=str, help='文件后缀') parser.add_argument('width', type=int, default=0, help='图片宽') parser.add_argument('height', type=int, default=0, help='图片高') parser.add_argument('force', type=str, default="resize", help='处理类型(resize,中心裁剪:crop_center:1)') parser.add_argument('resample', type=int, default=1, help='重新采样使用的方法') parser.add_argument('quality', type=int, default=100, help='图片质量') args = parser.parse_args() resource = ResourceDomain().get(id) if imagelib.is_img(resource.extension): file = mongolib.get(resource.blob_id) if not args["format"]: args["format"] = file.extension byte_io = imagelib.thumbnail(io.BytesIO(file.read()), **args) return send_file(byte_io, mimetype=imagelib.to_mimetype( args["format"])) # mimetype=file.content_type return "Error image type."
def detail(id): # id = request.args.get("id") return jsonify(ResourceDomain().get(id))
def raw(id): resource = ResourceDomain().get(id) # im = Image.open(io.BytesIO(blob.blob.read())) file = mongolib.get(resource.blob_id) return send_file(io.BytesIO(file.read()), mimetype=file.content_type)
def update(id): # title 和 tags result = ResourceDomain().update(id, **request.form) return jsonify(result)
def list(index=1): result = ResourceDomain().list(index=index, **request.args) return jsonify(result)