Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,10 +18,25 @@ if uploaded_file is not None:
|
|
| 18 |
# Send the file to the server using requests
|
| 19 |
response = requests.put(server_url, data=uploaded_file.read())
|
| 20 |
|
|
|
|
| 21 |
if response.status_code == 200:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
else:
|
| 26 |
st.write("Failed to upload the file.")
|
| 27 |
st.write(response.text)
|
|
|
|
| 18 |
# Send the file to the server using requests
|
| 19 |
response = requests.put(server_url, data=uploaded_file.read())
|
| 20 |
|
| 21 |
+
# Check if the file was uploaded successfully
|
| 22 |
if response.status_code == 200:
|
| 23 |
+
try:
|
| 24 |
+
# Parse the response JSON to extract the file ID
|
| 25 |
+
response_json = response.json()
|
| 26 |
+
file_id = response_json.get("id", None)
|
| 27 |
+
|
| 28 |
+
if file_id:
|
| 29 |
+
# Display success message and file link
|
| 30 |
+
st.write("File uploaded successfully!")
|
| 31 |
+
file_url = f"https://buzzheavier.com/f/{file_id}"
|
| 32 |
+
st.write(f"[View uploaded file]({file_url})")
|
| 33 |
+
else:
|
| 34 |
+
st.write("File uploaded, but no file ID returned.")
|
| 35 |
+
st.write(response.text)
|
| 36 |
+
except ValueError:
|
| 37 |
+
# Handle case where response isn't JSON formatted
|
| 38 |
+
st.write("Failed to parse the server response.")
|
| 39 |
+
st.write(response.text)
|
| 40 |
else:
|
| 41 |
st.write("Failed to upload the file.")
|
| 42 |
st.write(response.text)
|