Пример #1
0
def sign_up_photo_upload(class_name, name):
    f1 = open("/var/www/demoapp/test_result.txt", 'w')

    name = request.form.get('name', 'little apple')
    class_name = request.form.get('class_name', 'little apple')

    file_stream = request.form.get("image01")

    f1.write(str(class_name) + " " + str(name) + " " + str(file_stream))
    f1.close()

    new_path = "/var/www/demoapp/Accounts/" + class_name + "/" + name

    if os.path.exists(new_path) == False:
        os.makedirs(new_path)

        # Create the document storing CSV File, which used to recored customs' Travel coordinations
        new_csv_path = new_path + "/" + "coordinations"
        os.makedirs(new_csv_path)

        new_orijpg_path = new_path + "/" + "OriJPG"
        os.makedirs(new_orijpg_path)

    dirpath = '/var/www/demoapp'

    upload_file = request.files['image01']

    if upload_file and allowed_file(upload_file.filename):

        filename = secure_filename(upload_file.filename)
        upload_file.save(
            os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename))

        sign_up_photo_path = dirpath + "/student_photo/" + str(
            upload_file.filename)
        move_to_path = dirpath + "/Accounts/" + class_name + '/' + name + '/' + "OriJPG"
        shutil.move(sign_up_photo_path, move_to_path)
        """Description: the orders following are used to check if the scripts have been correctly executed

        >>>log_file = open('/var/www/demoapp/log.txt', mode='a')
        >>>log_file.write("---shutil.move Ok !---")

        """

        IP = request.remote_addr

        dir = '/var/www/demoapp/Accounts'

        pic_file_type = 'jpeg'

        extractProcess(upload_file.filename, dir, class_name, name, detector,
                       pic_file_type)

        return "Success"
    else:
        return "Fail"
Пример #2
0
def sign_up_photo_upload_base64(class_name, name):
    f1 = open("/var/www/demoapp/test_result.txt", 'w')

    file_stream = request.form.get("image01")

    f1.write(str(class_name) + " " + str(name) + " " + str(file_stream))
    f1.close()

    new_path = "/var/www/demoapp/Accounts/" + class_name + "/" + name

    base64_data_bytes = file_stream.encode("utf-8")
    base64_decode = base64.b64decode(base64_data_bytes)

    if os.path.exists(new_path) == False:
        os.makedirs(new_path)

        # Create the document storing CSV File, which used to recored customs' Travel coordinations
        new_csv_path = new_path + "/" + "coordinations"
        os.makedirs(new_csv_path)

        new_ori_jpg_path = new_path + "/" + "OriJPG"
        os.makedirs(new_ori_jpg_path)

    dirpath = '/var/www/demoapp'

    pic_file_type = 'jpeg'

    filename = name + '.' + pic_file_type

    move_to_path = dirpath + "/Accounts/" + class_name + '/' + name + '/' + "OriJPG" + '/' + filename
    image = io.BytesIO(base64_decode)
    img = Image.open(image)
    img.save(move_to_path)

    IP = request.remote_addr

    dir = '/var/www/demoapp/Accounts'

    extractProcess(filename, dir, class_name, name, detector, pic_file_type)

    return "Success"