'Tkinter: Share files in a chat app like we did in whatsapp or any other chatting app

I have created a simple chatting app using python tkinter to build front end and using PHP for backend for now it is only sending and receiving messages but I want to add some more functionality in to it I want to share files as well.

To achieve file sharing functionality I used filedialog.askopenfilename() function to get file from computer and I can successfully upload the file on server, but the issue is how can I show that file on as a downloadable link on chatbox like in whatsapp when we send file to anyone he/she can firstly download and then open it?

Below is my code where I am uploading file to server:

def open_file ( self ) :

    file = filedialog.askopenfilename ( )
    file = pathlib.PurePath ( file )
    filename = os.path.basename ( file )
    fob = open ( file , encoding = "Latin-1" )
    upload_file = [ ("files" , (filename , fob , 'file/docx')) ]
    post = { 'file' : upload_file }
    response = requests.post ( url , files = upload_file , data = post )
    print ( filename )
    print ( upload_file )
    fob.close ( )

    if file is not None :
        pr2 = em_info + ":" + " " + filename + "\n"
        self.text_box.configure ( state = NORMAL )
        self.text_box.insert ( END , pr2 , "left" )
        self.text_box.tag_configure ( "left" , justify = 'left' )
        self.text_box.tag_configure ( "left" , foreground = 'slate blue2' )
        # self.text_box.tag_add("left", 1.0, "end")
        self.text_box.configure ( state = DISABLED )
        self.text_box.see ( END )
        self.entry_field.delete ( 0 , END )


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source