Update the uplaod function
This commit is contained in:
parent
04145b89c4
commit
adf54839c9
@ -2,6 +2,10 @@ import os
|
|||||||
import cherrypy
|
import cherrypy
|
||||||
|
|
||||||
def main(file, rename, directory):
|
def main(file, rename, directory):
|
||||||
|
try:
|
||||||
|
os.makedirs(directory, exist_ok=True)
|
||||||
|
except OSError as error:
|
||||||
|
print(error)
|
||||||
try:
|
try:
|
||||||
upload_path = directory
|
upload_path = directory
|
||||||
upload_filename = file.filename
|
upload_filename = file.filename
|
||||||
@ -9,6 +13,15 @@ def main(file, rename, directory):
|
|||||||
upload_file = os.path.normpath(os.path.join(upload_path, upload_rename))
|
upload_file = os.path.normpath(os.path.join(upload_path, upload_rename))
|
||||||
upload_size = 0
|
upload_size = 0
|
||||||
|
|
||||||
|
print("UPLOADING CORE: Directory: "+directory+"/"+rename)
|
||||||
|
if (os.path.isfile(directory+"/"+rename)):
|
||||||
|
print("UPLOADING CORE: Is exists! Removing!")
|
||||||
|
try:
|
||||||
|
os.remove(directory+"/"+rename)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"UPLOADING CORE: removing failed: {e}")
|
||||||
|
else:
|
||||||
|
print("UPLOADING CORE: Is not exists! Removing skipped!")
|
||||||
with open(upload_file, 'wb') as upload_result:
|
with open(upload_file, 'wb') as upload_result:
|
||||||
while True:
|
while True:
|
||||||
data = file.file.read(8192)
|
data = file.file.read(8192)
|
||||||
@ -24,4 +37,4 @@ def main(file, rename, directory):
|
|||||||
print("UPLOAD SIZE: " + str(upload_size))
|
print("UPLOAD SIZE: " + str(upload_size))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"ERROR: {e}")
|
print(f"ERROR CORE UPLOADING: {e}")
|
||||||
|
Loading…
Reference in New Issue
Block a user