def download_thumbnail(path): tb_path = thumbnail_path(path) data = FS.download(tb_path) if not data: origin, params = parse_thumbnail_path(path) data = FS.download(origin) if not data: return "" data = create_thumbnail(data, params) r = FS.upload(tb_path, data) if not r: return "" return data
def download_mp3(audio_path): path = "/audios/" + audio_path + ".mp3" data = FS.download(path) if not data: path = "/audios/" + audio_path amr_data = FS.download(path) if amr_data: data = amr_to_mp3(amr_data) path = "/audios/" + audio_path + ".mp3" FS.upload(path, data) if not data: return make_response(400) else: return data
def download_file(audio_path): path = "/audios/" + audio_path data = FS.download(path) if not data: return make_response(400) else: return data
def upload_form_image(): if 'file' not in request.files: return make_response(400) f = request.files['file'] content_type = f.headers.get("Content-Type", '') ext = image_ext(content_type) if not ext: return make_response(400, {"error": "can't get image extenstion"}) data = f.read() if not data: return make_response(400, {"error": "data is null"}) name = hashlib.md5(data).hexdigest() path = "/images/" + name + ext r = FS.upload(path, data) if not r: return make_response(400, {"error": "upload file fail"}) url = request.url_root + "images/" + name + ext src = "/images/" + name + ext obj = {"src": src, "src_url": url} return make_response(200, data=obj)
def upload_form_image(): if 'file' not in request.files: return make_response(400) f = request.files['file'] content_type = f.headers["Content-Type"] if f.headers.has_key("Content-Type") else "" ext = image_ext(content_type) if not ext: return make_response(400, {"error":"can't get image extenstion"}) data = f.read() if not data: return make_response(400, {"error":"data is null"}) name = md5.new(data).hexdigest() path = "/images/" + name + ext r = FS.upload(path, data) if not r: return make_response(400, {"error":"upload file fail"}) url = request.url_root + "images/" + name + ext src = "/images/" + name + ext obj = {"src":src, "src_url":url} return make_response(200, data=obj)
def download_file(file_path): path = "/files/" + file_path data = FS.download(path) if not data: return make_response(400) else: return data
def download_file(file_path): content_type, _ = mimetypes.guess_type(file_path) path = "/files/" + file_path data = FS.download(path) if not data: return flask.make_response("", 404) else: res = flask.make_response(data, 200) if content_type is None: content_type = "application/octet-stream" res.headers['Content-Type'] = content_type return res
def upload_file(): if not request.data: return NO_CONTENT() md5_value = hashlib.md5(request.data).hexdigest() path = "/audios/" + md5_value r = FS.upload(path, request.data) if not r: return make_response(400) else: obj = {} url = request.url_root + "audios/" + md5_value src = "/audio/" + md5_value obj["src"] = src obj["src_url"] = url return make_response(200, obj)
def upload_file(): if not request.data: return NO_CONTENT() md5_value = md5.new(request.data).hexdigest() path = "/audios/" + md5_value r = FS.upload(path, request.data) if not r: return make_response(400) else: obj = {} url = request.url_root + "audios/" + md5_value src = "/audio/" + md5_value obj["src"] = src obj["src_url"] = url return make_response(200, obj)
def download_image(image_path): path = "/images/" + image_path if is_thumbnail(path): data = download_thumbnail(path) else: data = FS.download(path) if not data: return flask.make_response("", 400) else: res = flask.make_response(data, 200) if image_path.endswith(".jpg"): res.headers['Content-Type'] = "image/jpeg" elif image_path.endswith(".png"): res.headers['Content-Type'] = "image/png" else: logging.info("invalid image type") return res
def download_image(image_path): print image_path path = "/images/" + image_path if is_thumbnail(path): data = download_thumbnail(path) else: data = FS.download(path) if not data: return flask.make_response("", 400) else: res = flask.make_response(data, 200) if image_path.endswith(".jpg"): res.headers['Content-Type'] = "image/jpeg" elif image_path.endswith(".png"): res.headers['Content-Type'] = "image/png" else: print "invalid image type" return res
def upload_image(): if not request.data: return make_response(400) content_type = request.headers["Content-Type"] if request.headers.has_key("Content-Type") else "" ext = image_ext(content_type) if not ext: return make_response(400) data = request.data name = md5.new(data).hexdigest() path = "/images/" + name + ext r = FS.upload(path, data) if not r: return make_response(400) url = request.url_root + "images/" + name + ext src = "/images/" + name + ext obj = {"src":src, "src_url":url} return make_response(200, data=obj)
def upload_image(): if not request.data: return make_response(400) content_type = request.headers.get("Content-Type", '') ext = image_ext(content_type) if not ext: return make_response(400) data = request.data name = hashlib.md5(data).hexdigest() path = "/images/" + name + ext r = FS.upload(path, data) if not r: return make_response(400) url = request.url_root + "images/" + name + ext src = "/images/" + name + ext obj = {"src": src, "src_url": url} return make_response(200, data=obj)
def upload_image(): if not request.data: return make_response(400) content_type = request.headers["Content-Type"] if request.headers.has_key( "Content-Type") else "" ext = image_ext(content_type) if not ext: return make_response(400) data = request.data name = md5.new(data).hexdigest() path = "/images/" + name + ext r = FS.upload(path, data) if not r: return make_response(400) url = request.url_root + "images/" + name + ext src = "/images/" + name + ext obj = {"src": src, "src_url": url} return make_response(200, data=obj)
def upload_form_file(): if 'file' not in request.files: return NO_CONTENT() f = request.files['file'] data = f.read() if not data: return NO_CONTENT() md5_value = hashlib.md5(data).hexdigest() path = "/audios/" + md5_value r = FS.upload(path, data) if not r: return make_response(400, {"error": "upload file fail"}) obj = {} url = request.url_root + "audios/" + md5_value src = "/audio/" + md5_value obj["src"] = src obj["src_url"] = url return make_response(200, obj)
def upload_form_file(): if 'file' not in request.files: return NO_CONTENT() f = request.files['file'] data = f.read() if not data: return NO_CONTENT() md5_value = md5.new(data).hexdigest() path = "/audios/" + md5_value r = FS.upload(path, data) if not r: return make_response(400, {"error":"upload file fail"}) obj = {} url = request.url_root + "audios/" + md5_value src = "/audio/" + md5_value obj["src"] = src obj["src_url"] = url return make_response(200, obj)
def upload_file(): if 'file' not in request.files: return NO_CONTENT() #keep file extention f = request.files['file'] _, ext = os.path.splitext(f.filename) data = f.read() if not data: return NO_CONTENT() md5_value = md5.new(data).hexdigest() filename = md5_value + ext path = "/files/" + filename r = FS.upload(path, data) if not r: return make_response(400, {"error": "upload file fail"}) obj = {} url = request.url_root + "files/" + filename src = "/files/" + filename obj["src"] = src obj["src_url"] = url return make_response(200, obj)
def upload_file(): if 'file' not in request.files: return NO_CONTENT() #keep file extention f = request.files['file'] _, ext = os.path.splitext(f.filename) data = f.read() if not data: return NO_CONTENT() md5_value = md5.new(data).hexdigest() filename = md5_value + ext path = "/files/" + filename r = FS.upload(path, data) if not r: return make_response(400, {"error":"upload file fail"}) obj = {} url = request.url_root + "files/" + filename src = "/files/" + filename obj["src"] = src obj["src_url"] = url return make_response(200, obj)