Hi,
I'm not expert but I have found this to be a really challenging issue, especially if you need to maintain a unique Link (e.g. if you have Unique Document ID turned on), and if you want to maintain the document metadata.
In my solution, I am using a Powerapp to provide a document management function using Sharepoint document libraries and had to use several flows to get it working.
I didn't find the answer in any one forum, but have managed to cobble together a working process so thought I'd share it:
1. Change the file name in Sharepoint
You can only effectively replace a file if the file name is identical. If you try to upload a file with a different name, it will create a separate file rather than replacing the one you want to change. If you delete the file and create a new one, then the old ID and metadata are lost...
If the file you want to upload has a different filename (e.g. if original file is Filename1 v1.pdf and the new file is Filename v2.pdf), you will need to change the file name first.
I then set a check to see if the uploaded file name matched the existing file name.
NB: I had to use a 4 second timer and a 'pls wait' message before refreshing the data source so that the app would know that the two now had the same name.
2. Upload the file
Once the file names matched, then I went back to Matthew's guide to creating the flow to upload the file.
You need to disable the content transfer slider on the 'create file' step of your flow to enable overwrite of an existing file.
Hey presto - you have now got a new file with the same meta data and the same document ID link. NB: If using Document ID - There is a delay of about 5-10 minutes for the Document ID link to update. You will see a '404 error' if you try to use the link before the update is complete. I had to add a user message to this effect.
Hope that helps,
Jem