Spaces:
Sleeping
Sleeping
Commit
·
155475c
1
Parent(s):
3c9a698
test: poc parse metadata
Browse files- apis/s3.py +1 -1
- app.py +5 -4
apis/s3.py
CHANGED
@@ -33,7 +33,7 @@ class S3:
|
|
33 |
return [self.client.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': key}) for key in image_keys]
|
34 |
|
35 |
# Function to upload file to S3
|
36 |
-
def upload_file(self, bucket_name, file, name, metadata):
|
37 |
res = Response()
|
38 |
try:
|
39 |
# self.client.upload_fileobj(
|
|
|
33 |
return [self.client.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': key}) for key in image_keys]
|
34 |
|
35 |
# Function to upload file to S3
|
36 |
+
def upload_file(self, bucket_name, file, name, metadata:dict):
|
37 |
res = Response()
|
38 |
try:
|
39 |
# self.client.upload_fileobj(
|
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
from http import HTTPStatus
|
2 |
import os, io, base64, json
|
3 |
-
from typing import Optional
|
4 |
from fastapi.responses import JSONResponse
|
5 |
from typing_extensions import Annotated
|
6 |
import uvicorn
|
@@ -71,7 +71,6 @@ async def upload(
|
|
71 |
x_api_key: str = Header(...),
|
72 |
metadata: str = Header(...),
|
73 |
):
|
74 |
-
print(metadata)
|
75 |
res = Response()
|
76 |
logging.info("--------------------------------")
|
77 |
logging.info(f"Received request to upload image by {x_request_user}")
|
@@ -81,9 +80,11 @@ async def upload(
|
|
81 |
logging.info(f'Key for S3 upload: {key}')
|
82 |
if o.content is not None:
|
83 |
try:
|
84 |
-
metadata = json.loads(metadata)
|
85 |
-
|
|
|
86 |
metadata = {}
|
|
|
87 |
|
88 |
try:
|
89 |
# Decode base64 content
|
|
|
1 |
from http import HTTPStatus
|
2 |
import os, io, base64, json
|
3 |
+
from typing import Any, Dict, Optional
|
4 |
from fastapi.responses import JSONResponse
|
5 |
from typing_extensions import Annotated
|
6 |
import uvicorn
|
|
|
71 |
x_api_key: str = Header(...),
|
72 |
metadata: str = Header(...),
|
73 |
):
|
|
|
74 |
res = Response()
|
75 |
logging.info("--------------------------------")
|
76 |
logging.info(f"Received request to upload image by {x_request_user}")
|
|
|
80 |
logging.info(f'Key for S3 upload: {key}')
|
81 |
if o.content is not None:
|
82 |
try:
|
83 |
+
metadata: Dict[str, Any] = json.loads(metadata)
|
84 |
+
logging.info(metadata)
|
85 |
+
except Exception as e:
|
86 |
metadata = {}
|
87 |
+
logging.info(f'Error: {str(e)}\nUse default metadata instead.')
|
88 |
|
89 |
try:
|
90 |
# Decode base64 content
|