summaryrefslogtreecommitdiffstats
path: root/test.py
blob: 81f35d3012e908d15c181d4f03266e1a517913a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# import os
# fi = form['filename']
# if fi.filename:
# 	# This code will strip the leading absolute path from your file-name
# 	fil = os.path.basename(fi.filename)
# 	# open for reading & writing the file into the server
# 	open(fn, 'wb').write(fi.file.read())
#

# import requests
# dfile = open("datafile.txt", "rb")
# url = "http://httpbin.org/post"
# test_res = requests.post(url, files = {"form_field_name": dfile})
# if test_res.ok:
#     print(" File uploaded successfully ! ")
#     print(test_res.text)
# else:
#     print(" Please Upload again ! ")

# from filestack import Client
# c = Client("API's Key")
# filelnk = c.upload(filepath = '/path/of/file.png')
# print(filelnk.url)

from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import FileField, SubmitField
from werkzeug.utils import secure_filename
import os
from wtforms.validators import InputRequired

app = Flask(__name__)
app.config['SECRET_KEY'] = 'supersecretkey'
app.config['UPLOAD_FOLDER'] = 'static/files'

class UploadFileForm(FlaskForm):
    file = FileField("File", validators=[InputRequired()])
    submit = SubmitField("Upload File")

@app.route('/', methods=['GET',"POST"])
@app.route('/home', methods=['GET',"POST"])
def home():
    form = UploadFileForm()
    if form.validate_on_submit():
        file = form.file.data # First grab the file
        file.save(os.path.join(os.path.abspath(os.path.dirname(__file__)),app.config['UPLOAD_FOLDER'],secure_filename(file.filename))) # Then save the file
        return "File has been uploaded."
    return render_template('index.html', form=form)

if __name__ == '__main__':
    app.run(debug=False)

# class Label:
#     def __init__(self, val, path=None):
#         self.value = val[0].split('=')[0]
#         if "self." in self.value:
#             ind = self.value.index("self.")
#             self.value= self.value[ind + 5:]
#         self.path = path
#
#     def out(self):
#         if self.path is None:
#             print(globals()[self.value])
#         else:
#             eval("print(self.path.%s)" % self.value)
#
# class Game:
#     def __init__(self):
#         self.score = 0
#         self.label = Label([f'{self.score=}'], self)
#
#     def out(self):
#         print(self.score)
#         self.label.out()
#
#     def increase(self):
#         self.score += 1
#
#
# x = Game()
#
# x.out()
# for i in range(3):
#     x.increase()
#     x.out()
#
# a = 100
# y = Label([f"{a=}"])
#
# y.out()
#
# a += 10
#
# y.out()