Merge branch 'master' into 4-mongodb_api

# Conflicts:
#	middleware/app_be/views/rest_api.py
This commit is contained in:
Manuel Hude
2020-12-06 14:24:01 +01:00
13 changed files with 154 additions and 47 deletions
@@ -0,0 +1,7 @@
import hashlib
def create_sha512(b: bytes):
h = hashlib.sha512()
h.update(b)
return h.hexdigest()
@@ -0,0 +1,41 @@
import requests
from django.conf import settings
class MinioService:
@staticmethod
def create_file(filename: str, file: bytes) -> bool:
"""Create / save (or overwrite) an file on the minio storage.
:param filename: filename
:param file: bytes representation of the file
:return: Whether file was successfully uploaded
"""
try:
url= settings.AWS_HOST + filename
headers = {'Content-Type': 'binary/octet-stream'}
r = requests.put(url,data=file,headers=headers)
if r.status_code == 200:
print("Successfully uploaded a file!")
else:
print("Something went wrong")
except:
return False
return True
@staticmethod
def read_file(filename: str) -> bytes:
"""Read file on the minio storage.
:param filename: filename
:return: bytes representation of the file or None on error
"""
file_bytes: bytes
try:
url = settings.AWS_HOST + filename
response = requests.get(url, stream=True)
file_bytes=response.content
except:
print("Error downloading file from minio")
return file_bytes
+1 -1
View File
@@ -6,7 +6,7 @@ class WrapperService:
@staticmethod
def wrap_file(file_bytes: bytes) -> str:
file_encoded_b64 = base64.b64encode(file_bytes)
return file_encoded_b64.decode('utf-8')
return file_encoded_b64.decode()
@staticmethod
def unwrap_file(file_str: str) -> bytes: