示例#1
0
def upload_file():
    # check if the post request has the file part
    if 'file' not in request.files:
        return jsonify(code=1002, result="File can't empty!")
    file_instance = request.files['file']
    if file_instance.filename == '':
        return jsonify(code=1002, result="File name can't empty!")
    if file_instance and common.allowed_file(file_instance.filename):
        filename = secure_filename(file_instance.filename)
        file_instance.save(os.path.join(os.path.join(config.Config('upload', 'directory').value, 'uploads'), filename))
        # scan job
        code, result = scan.Scan(filename).compress()
        return jsonify(code=code, result=result)
    else:
        return jsonify(code=1002, result="This extension can't support!")
示例#2
0
def upload_file():
    """
    Scan by uploading compressed files
    :return:
    """
    if 'file' not in request.files:
        return jsonify(code=1002, result="File can't empty!")
    file_instance = request.files['file']
    if file_instance.filename == '':
        return jsonify(code=1002, result="File name can't empty!")
    if file_instance and common.allowed_file(file_instance.filename):
        filename = secure_filename(file_instance.filename)
        file_instance.save(os.path.join(os.path.join(config.Config('upload', 'directory').value, 'uploads'), filename))
        # Start scan
        code, result = scan.Scan(filename).compress()
        return jsonify(code=code, result=result)
    else:
        return jsonify(code=1002, result="This extension can't support!")
示例#3
0
def test_allowed_file():
    assert common.allowed_file('test01/test02/file.rar') is True