-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadScreenshot.py
More file actions
26 lines (22 loc) · 1005 Bytes
/
uploadScreenshot.py
File metadata and controls
26 lines (22 loc) · 1005 Bytes
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
# --------------------------------------------------------------------------------------------------------
# IMPORTING LIBRARIES
import mysql.connector as connection
import connectMysql as conn
# --------------------------------------------------------------------------------------------------------
# Convert images or files data to binary format
def convert_data(filename):
with open(filename, 'rb') as file:
binary_data = file.read()
return binary_data
def uploadSS(mydb, filename):
mycursor = mydb.cursor()
try:
# INSERTION QUERY
query = """INSERT INTO SCREENSHOT(Filename, IMAGE) VALUES (%s, %s)"""
image = convert_data(filename)
result = mycursor.execute(query, (filename, image))
mydb.commit()
except connection.Error as error:
print(error)
with open("log.txt", "a") as f:
f.write("\n\nCould not upload file to MySQL server. \n\n")