-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadFirebase.py
More file actions
30 lines (23 loc) · 904 Bytes
/
Copy pathuploadFirebase.py
File metadata and controls
30 lines (23 loc) · 904 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
27
28
29
30
import datetime
def uploadToFirebase(storage, path_on_system, filetype):
# go to specific folder depending on file type
if filetype == 1: # text file
path_on_cloud = "text/"
elif filetype == 2: # video file
path_on_cloud = "videos/"
else:
path_on_cloud = "misc/"
# Check if '/' is present in the path
if '/' in path_on_system:
pos1 = path_on_system.rindex('/')
else:
pos1 = -1
pos2 = path_on_system.rindex('.')
# Get the current date and time
now = datetime.datetime.now()
# Format the date and time to be used in the filename
formatted_now = now.strftime("%Y-%m-%d_%H-%M-%S")
# append the original filename
path_on_cloud = path_on_cloud + path_on_system[ pos1 + 1 : pos2] + formatted_now + path_on_system[pos2:]
# upload
storage.child(path_on_cloud).put(path_on_system)