volesen / flask-tus

MIT License
6 stars 2 forks source link

Changing the filename on complete #4

Open eokeeffe opened 3 years ago

eokeeffe commented 3 years ago

Just wanted to start, thank you for the package, it works great!

I was wondering about the on_complete method, I'm looking to change the filename when the file completes the upload. I see the filename is being sent in the metadata in the header.

I'm not sure where to start though with changing the filename on completion. Do I do this through the FlaskTus object or do I need to do this through the monogdb script side?

Thanks again for the great system you made!

eokeeffe commented 3 years ago

I was able to find a way to do it. Involved changing the constructor for on_complete in flask_tus/app.py

def on_complete(self,):  
    pass  

to

def on_complete(self, upload_uuid=None):  
    pass  

then in FlaskTusExtended you can overwrite the original function with something like

    def on_complete(self,upload_uuid=None):  
            if(upload_uuid==None):  
                 return
            upload = self.repo.find_by(upload_uuid=upload_uuid)[0]
            uuid = upload.upload_uuid
            path = upload.path
            original_filename = upload.filename
            #code to change the file on system to the original name

This allows you to configure the way you want to manage the file name after download completes. Is there an easier way of create a mongodb database object that would represent the metadata you want to contain to use in filesystem management?

Thanks again