Can not prevent uploading of specific files

Hi everyone!

I figured out how to prevent uploading of zip files using Files access control. I just wrote in Custom MIME type - /^application/(zip)$/i
But how to prevent uploading other types of files like rar, prt, sldprt and others?
If I’m trying to use /^application\/(rar)$/i or /^application\/(prt)$/i is does not work.

Am I doing something wrong?

UPD: i tried to ask ChatGPT and it said to try to change config.php so i added this:

    2 =>
    array (
      'sldprt' => 'application/sldprt',
      'prt' => 'application/prt',
    ),

it does not fixed my problem.

I wouldn’t make changes to your config.php because a silly chat bot said to…

Are you trying to block these files or just stop the client from syncing them? The client can exclude files based on name pattern. What you did above I think is for MIME types.

I’m trying to block specific file types using Files access control

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

As i said, it’s working only for zip files but i need to restrict other type of files .

Not tested.

The MIME type of a .zip file is application/zip.
The MIME type of a .rar file is application/x-rar-compressed.

source

Test for rar:
/^application\/(x-rar-compressed)$/i

application/pro_eng

source

Test for prt:
/^application\/(pro_eng)$/i

2 Likes

Try the following:

/^application\/(rar|vnd.rar|x-rar-compressed)$/i

EDIT:

if it still doesn’t work, try adding octet-stream as an additional MIME type, like this:

/^application\/(rar|vnd.rar|x-rar-compressed|octet-stream)$/i

https://stackoverflow.com/questions/6977544/rar-zip-files-mime-type

1 Like

I tested it, and the following one-liner works on my test instance, for both, rar and zip files:

/^application\/(rar|vnd.rar|x-rar-compressed|octet-stream|zip|x-zip-compressed)$/i
2 Likes

beware of octet-stream it fits many binary formats - depending on what you are looking for this might affect more than you wanted…

1 Like

Thank you so much!

1 Like

So… how to find proper MIME type?

Use the command “file --mime-type <file>” to find out the mime type of a file.

where to type it?

On the Linux console or on your Windows PC if you’ve installed it.
See e.g. How can I find out a files “mime-type(Content-Type?)”? on Windows - Stack Overflow