Пример #1
0
def upload_endpoint():
    if request.method == 'POST':
        if 'file' not in request.files:
            return jsonify({"error": boilerplate.ERROR_NO_FILE_PART})
        upload_file = request.files['file']
        if upload_file.filename == '':
            return jsonify({"error": boilerplate.ERROR_NO_SELECTED_FILE})
        if upload_file and boilerplate.allowed_file(
                upload_file.filename, allowed_extensions=ALLOWED_EXTENSIONS):
            return jsonify(boilerplate.save_file(upload_file))
    return boilerplate.get_upload_form()
Пример #2
0
def upload_file(file_name, file_contents_base64):
    if not file_name:
        raise JSONRPCDispatchException(code=boilerplate.ERROR_NO_SELECTED_FILE_CODE, message=boilerplate.ERROR_NO_SELECTED_FILE)
    if not file_contents_base64:
        raise JSONRPCDispatchException(code=boilerplate.ERROR_NO_FILE_PART_CODE, message=boilerplate.ERROR_NO_FILE_PART)
    if not boilerplate.allowed_file(file_name, allowed_extensions=ALLOWED_EXTENSIONS):
        raise JSONRPCDispatchException(code=boilerplate.ERROR_NOT_ALLOWED_CODE, message=boilerplate.ERROR_NOT_ALLOWED)
    try:
        file_contents = b64decode(file_contents_base64)
        file_size = len(file_contents)
    except TypeError:
        raise JSONRPCDispatchException(code=boilerplate.ERROR_NO_FILE_PART_CODE, message=boilerplate.ERROR_NO_FILE_PART)
    return boilerplate.save_file_simple(file_name, file_contents, file_size)
Пример #3
0
def upload_endpoint():
    if request.method == 'POST':
        uploaded_files = request.files.getlist("file[]")
        # upload_file = request.files['file']
        # make upload for few files
        result_upload_file = {}
        for num, upload_file in enumerate(uploaded_files):
            if uploaded_files[num].filename == '':
                return jsonify({"error": boilerplate.ERROR_NO_SELECTED_FILE})
            if uploaded_files[num] and boilerplate.allowed_file(
                    uploaded_files[num].filename,
                    allowed_extensions=ALLOWED_EXTENSIONS):
                result_done = boilerplate.save_file(uploaded_files[num])
                result = {str(num): result_done}
                result_upload_file.update(result)
        return jsonify(result_upload_file)
    return boilerplate.get_upload_form()