File size: 1,311 Bytes
ce2b60c
 
 
 
 
 
f649951
 
ce2b60c
 
 
 
 
 
 
 
 
 
 
 
9ad5d28
 
 
 
fc5ba53
9ad5d28
 
 
6f040ad
 
7ccb1e7
9ad5d28
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import streamlit as st
import requests

# Streamlit file uploader interface
st.title("File Uploader")

# Allow all file types by setting type=None
uploaded_file = st.file_uploader("Choose a file")

if uploaded_file is not None:
    # File details
    file_details = {"filename": uploaded_file.name, "filetype": uploaded_file.type}
    st.write(file_details)

    # Define the server URL and the name under which the file will be stored
    server_url = f"https://w.buzzheavier.com/t/{uploaded_file.name}"

    # Send the file to the server using requests
    response = requests.put(server_url, data=uploaded_file.read())

    # Parse the JSON response to get the file ID
    try:
        response_data = response.json()
        file_id = response_data.get("id")

        if file_id:
            file_link = f"https://buzzheavier.com/f/{file_id}"
            if response.status_code == 200:
                st.write("File uploaded successfully!")
            else:
                st.write("File uploaded successfully!")
            # Display the link to the file
            st.markdown(f"[View your file here]({file_link})")
        else:
            st.write("Unexpected response format. No file ID found.")
    except ValueError:
        st.write("Failed to upload the file. Received an invalid response.")