Copy Mattermost File uploads into a defined Nextcloud Folder

Hello @ all,
a lot of people are sharing Files via Mattermost chat. And for us it is okay, because it is a fast way to share this files.

But our users want to have the Files also in our Nextcloud. So the wish is:

“When I upload a file via Mattermost into a chat, can you directly make a copy of this file and put it into a Chat-folder of our nextcloud?”

For example:
For example: In Team “Development” the User “John” posts the file “JohnsStrategy.pdf” in the Channel “Backlog”.

The file “JohnsStategy.pdf” should be now directly also stored at the following Nextcloud-path:

Do somebody know how to implement this? Or is there an App/Extension/Webhook?

Thanks a lot!

Hi zugang,

I’m not aware of any method that would support that by default, but you could use an S3 bucket as the storage for your files and then, basically, the files will automatically be uploaded there in a somewhat similar file structure, although this has nothing to do with NextCloud then.

If the files need to be uploaded to NextCloud, I think you will have to script something on your own for that.
You would have to run searches for files using the API and if you found a new file, you would have to get it and store it into your NextCloud instance in a folder structure you previously defined.

Outgoing Webhooks do not react on files as far as I know, so only text messages are supported at the moment.
Would you be able to script something like that?

HI Agriesser,

thanks for your fast response!
Actually Im not able to script something like that. But the files are on the same server. Therefore also a crone-job can copy that.
But can you explain more in detail what a “S3” bucket is and how I can use this with mattermost?

The Mattermost data folder structure looks like this:


So if you want to watch a specific channel and get all the attachments from there, you would have to use some wildcards to achieve that. Every day, a new folder will be created (YYYYMMDD) and since you want to copy all attachments from all users for a given (or all?) channels, you will also have to use a wildcard on the userid.
Nextcloud does not like getting files injected on the command line as far as I know, so after copying a file to the Nextcloud directory, I think you will also have to rescan the files there so that the Nextcloud GUI can list the files.

Maybe there are other, better suited options but I think I’m still not understanding why you want to do that. Can you maybe elaborate a bit on the reason for this request?

An S3 bucket is a so-called object storage. Think of it as an online directory where you can upload files to (via the HTTP protocol) and also access them again via HTTP then.