Skip to content

Commit 1ec0c77

Browse files
committed
file_sender
1 parent 07624a2 commit 1ec0c77

4 files changed

Lines changed: 27 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Backend/requirements.txt
33
dat.txt
44
temp.txt
55
Backend/test.py
6+
main.py
1.83 KB
Binary file not shown.

Backend/file_sender.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import uvicorn
22
from fastapi import FastAPI
33
from fastapi import APIRouter
4+
import PyPDF2
5+
import base64
46
import boto3
5-
7+
import json
68

79
aws_access_key_id = 'AKIAZTHHIOR4JJ5HLTUB'
810
aws_secret_access_key = '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'
@@ -15,7 +17,7 @@
1517
getfiles = APIRouter()
1618

1719
@getfiles.post("/get_notes_txt")
18-
async def retrieve_files(email: str):
20+
async def retrieve_text_notes(email: str):
1921
# Configure your AWS credentials and region
2022

2123

@@ -36,7 +38,7 @@ async def retrieve_files(email: str):
3638
return {"files": files}
3739

3840
@getfiles.post("/get_notes_pdf")
39-
async def retrieve_files(email: str):
41+
async def retrieve_pdf_files(email: str):
4042
# Configure your AWS credentials and region
4143

4244

@@ -51,7 +53,25 @@ async def retrieve_files(email: str):
5153
for obj in response["Contents"]:
5254
file_key = obj["Key"]
5355
file_obj = s3_client.get_object(Bucket=bucket_name, Key=file_key)
54-
file_content = file_obj["Body"].read().decode("utf-8")
55-
files.append({"name": file_key, "content": file_content})
56+
file_content = file_obj["Body"].read()
57+
58+
# Encode the file content in base64
59+
encoded_content = base64.b64encode(file_content).decode("utf-8")
60+
files.append({"name": file_key, "content": encoded_content})
61+
62+
return {"files": files}
63+
64+
@getfiles.post("/cardData")
65+
def get_cardData(email: str):
66+
prefix = f"{email}/Cardjson"
5667

57-
return {"files": files}
68+
response = s3_client.list_objects_v2(Bucket=bucket_name, Prefix=prefix)
69+
70+
71+
if "Contents" in response:
72+
for obj in response["Contents"]:
73+
file_key = obj["Key"]
74+
file_obj = s3_client.get_object(Bucket=bucket_name, Key=file_key)
75+
file_content = file_obj["Body"].read().decode("utf-8")
76+
json_data = json.loads(file_content)
77+
return json_data

__pycache__/main.cpython-310.pyc

25 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)