Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -74,7 +74,7 @@ async def decrypt_and_upload(
|
|
74 |
):
|
75 |
try:
|
76 |
# Download file data from the URL
|
77 |
-
response = requests.get(url
|
78 |
if response.status_code != 200:
|
79 |
return JSONResponse(content={"error": "Failed to download the file."}, status_code=400)
|
80 |
|
@@ -87,11 +87,15 @@ async def decrypt_and_upload(
|
|
87 |
mediaKeyExpanded[16:48], mediaData[:-10], mediaKeyExpanded[:16]
|
88 |
)
|
89 |
|
90 |
-
#
|
91 |
-
|
|
|
|
|
|
|
|
|
92 |
decrypted_data,
|
93 |
-
resource_type=
|
94 |
-
format=
|
95 |
)
|
96 |
file_url = upload_result.get("url")
|
97 |
|
@@ -102,6 +106,7 @@ async def decrypt_and_upload(
|
|
102 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
103 |
|
104 |
|
|
|
105 |
# Root endpoint
|
106 |
@app.get("/")
|
107 |
def root():
|
|
|
74 |
):
|
75 |
try:
|
76 |
# Download file data from the URL
|
77 |
+
response = requests.get(url)
|
78 |
if response.status_code != 200:
|
79 |
return JSONResponse(content={"error": "Failed to download the file."}, status_code=400)
|
80 |
|
|
|
87 |
mediaKeyExpanded[16:48], mediaData[:-10], mediaKeyExpanded[:16]
|
88 |
)
|
89 |
|
90 |
+
# Determine Cloudinary upload parameters
|
91 |
+
resource_type = "video" if media_type.startswith("video") else "raw"
|
92 |
+
upload_format = extension.get(media_type, "bin")
|
93 |
+
|
94 |
+
# Upload decrypted data to Cloudinary
|
95 |
+
upload_result = cloudinary.uploader.upload(
|
96 |
decrypted_data,
|
97 |
+
resource_type=resource_type,
|
98 |
+
format=upload_format
|
99 |
)
|
100 |
file_url = upload_result.get("url")
|
101 |
|
|
|
106 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
107 |
|
108 |
|
109 |
+
|
110 |
# Root endpoint
|
111 |
@app.get("/")
|
112 |
def root():
|