-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsendsafely_python_workspace_example.py
More file actions
46 lines (35 loc) · 1.57 KB
/
sendsafely_python_workspace_example.py
File metadata and controls
46 lines (35 loc) · 1.57 KB
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
import json
from Workspace import Workspace
from sendsafely import SendSafely, Package
# Edit these variables
api_key = ""
api_secret = ""
packageCode = ""
keyCode = ""
base_url = "https://companyabc.sendsafely.com"
# Make sure all directories exist on your file system
upload_file = "fileToUpload.txt"
download_filename = "fileDownloaded.txt"
download_dir = "."
workspace_label = 'New Workspace'
def main():
sendsafely = SendSafely(base_url, api_key, api_secret)
workspace = Workspace(sendsafely, packageCode=packageCode,
keyCode=keyCode)
with open(upload_file, 'wb') as file:
content = bytes("SendSafely lets you easily exchange encrypted files and information with anyone on any device.", "utf-8")
file.write(content)
response=workspace.create_directory('new_folder')
print(json.dumps(response, indent=4, sort_keys=True))
f = workspace.encrypt_and_upload_file(upload_file, directory_name='new_folder')
file_id = f["fileId"]
print("Successfully encrypted and uploaded file id " + str(file_id))
files = workspace.list_workspace_files()
print(json.dumps(files, indent=4, sort_keys=True))
workspace.download_workspace_file(workspace_directory='new_folder', file_name=upload_file,
download_filename=download_filename)
print("Successfully downloaded and decrypted file " + download_filename)
response = workspace.delete_workspace_file(workspace_directory='new_folder', file_name=upload_file)
print("Successfully removed file")
if __name__ == '__main__':
main()