Accept files only with certain naming convention

i have a project where i want next-cloud to share files between some users, and these users will upload their files.

but i need these files to have a certain naming other wise next-cloud should not accept the upload and if this can be in certain folder with something like specific tag that would be awesome.

The naming convention like this:
SC1-SFT-V1-01-M3-A-S1-P02.pdf
with reg-ex like ^[a-zA-Z0-9]{2,6}-[a-zA-Z]{3,6}-[a-zA-Z0-9]{2}-[a-zA-Z0-9]{2}-[a-zA-Z0-9]{2}-[a-z A-Z]{1,2}-[a-zA-Z 0-9]{2,3}-[a-zA-Z0-9]{2,3}$

I am not sure how to do it in next-cloud, like can " Files Access Control " help me in this, or do i need to have a running script or what. i have a good programming skills with python that might helpful.

can someone please advise …


Nextcloud version: Nextcloud Hub 6 (27.1.3)
Operating system and version: Ubuntu 22.04
Install Method: Docker Container

https://docs.nextcloud.com/server/latest/admin_manual/file_workflows/access_control.html#prevent-uploading-of-specific-files

There should be an option for the filename as well (not just the mime type).

thank you @tflidd for your answer, but i have already tried that and here is what i did:

  • choose from Available flows the " Block access to a file "
  • choose filename for file to check
  • when choosing " matches " and paste my regex it complains about invalid configuration
  • when choosing " is " and paste my regex it passes and marks the rule as active, yet i can still upload files with other names than that naming convention.
    not sure if this rule is working correctly or not or is it running for some folders, as iam using group folders in my next-cloud

you tried it like this:
/^[a-zA-Z0-9]{2,6}-[a-zA-Z]{3,6}-[a-zA-Z0-9]{2}-[a-zA-Z0-9]{2}-[a-zA-Z0-9]{2}-[a-z A-Z]{1,2}-[a-zA-Z 0-9]{2,3}-[a-zA-Z0-9]{2,3}$/i


  1. a-zA-Z0-9 ↩︎

till now it does not work, so i have changed the “is” to “is not” as i need the rule to reject all other than this.

and it works by not letting my upload any file with different naming, but i also cloud not upload a file with exact naming.

so i guess the regex have a problem and i did try my version and your version too with no luck also, do you know a web page that can generate regex that php can work with and understand.

/^[a-zA-Z0-9]{2,6}-[a-zA-Z]{3,6}-[a-zA-Z0-9]{2}-[a-zA-Z0-9]{2}-[a-zA-Z0-9]{2}-[a-z A-Z]{1,2}-[a-zA-Z 0-9]{2,3}-[a-zA-Z0-9]{2,3}/i

I just removed the dollar sign (end of line). If you want to keep it, you might want to add the .pdf extension.


  1. a-zA-Z0-9 ↩︎

If you use the trailing i (which means “ignore case”), the regex can be made like this:

/^[a-z0-9]{2,6}-[a-z]{3,6}-[a-z0-9]{2}-[a-z0-9]{2}-[a-z0-9]{2}-[a-z ]{1,2}-[a-z 0-9]{2,3}-[a-z0-9]{2,3}/i

and then you should test your regex on → regex101 ← . There you wil find eventually errors verry fast.

Much luck,
ernolf

I am not sure exactly what is going on with nextcloud, everything i did doesn’t work till now.
this is what i did:

  • added the rule to block access to a file
    • i guess this works for every folder
    • i used is not instead of does not match – do not know the difference
  • now trying to upload any file without a match and nextcloud refuses which is good, but when trying to upload a file named exactly as it should like SC1-SFT-V1-01-M3-A-S1-P02.txt it refuses the file as well which is so weird ??? is this a bug ???
  • i have tried all of your suggestions for the reg-ex and also verified it is working with the website regex101

please advise …
many thanks .

i have found the solution and it is as you have said to before, it should be done like so:

  • create the block file access rule with:
    • File name, does not match, the reg-ex pattern (make sure no spaces here)
    • File MIME type, is not, Folder # just to make the rule apply for files only
    • File system tag, is tagged with, with-naming- convention # using tags to specifically select some folder out of the rest

it is now working correctly with these configs, but i need that naming within the specified folder and not recursively (i.e not within a folder within that folder). yet i do not know how to achieve that, so if anyone have an idea please share it or do i have to write a new question ???

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.