Project

General

Profile

Actions

Feature #103594

open

Allow specific file extensions per File Storage

Added by Marcelo Vetter 8 months ago. Updated 8 months ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
File Abstraction Layer (FAL)
Target version:
-
Start date:
2024-04-10
Due date:
% Done:

0%

Estimated time:
PHP Version:
8.1
Tags:
FAL, Block File Extension
Complexity:
easy
Sprint Focus:

Description

Let's image we have two File Storages set up:
  • Documents (/fileadmin/documents/*)
  • Images (/fileadmin/images/*)
I would like to only allow specific file types per File Storage:
  • Documents (.pdf, .doc, .docx, .etc...)
  • Images (.jpg, .jpeg, .png, .gif, .webp, .etc...)

I've created a simple BeforeFileAddedEvent listener (which I'm attaching here as an example). Below is a sample PageTS Config on the Page ID 1 Resources tab or on the user or user group Options tab:

permissions.file.storage {

  // 1 = Images Storage ID
  1 {
    allowedExtensions = jpg|jpeg|png|webp|gif|svg
    allowedExtensionsMsg = To upload a document, please use the Documents drive.
  }

  // 5 = Documents Storage ID
  5 {
    allowedExtensions = pdf|docx|doc|csv|xlsx|xls|pptx|ppt
    allowedExtensionsMsg = To upload an image, please use the Images drive.
  }

}

Is it doable to include something similar in the core of TYPO3?

Thanks!


Files

StorageExtensionBlocker.php (3.95 KB) StorageExtensionBlocker.php BeforeFileAddedEvent PHP file example Marcelo Vetter, 2024-04-10 21:37
Actions #1

Updated by Mathias Bolt Lesniak 8 months ago

Hi Marcelo!

Thank you for posting this, and for including a proof of concept PHP file!

I wonder about the use case for this and the reason for placing the configuration within PageTS or UserTS. Couldn't this configuration also be placed within the File Storage record? Or is it a specific requirement that the allowed files can be changed depending on the user or page?

— Mathias

Actions #2

Updated by Marcelo Vetter 8 months ago

Hi Mathias,

That's just a proof of concept as you mentioned.

I didn't search a way to add it directly to the File Storage record or even via TypoScript. If the configuration is done directly in the File Storage settings, that would be fine with me, and it makes a lot more sense!

However, having the flexibility to configure it per user or user groups would be for convenience in the future. In my situation, I might allow some users to upload videos as well in the Image/Media storage. All other users could only upload images.

Cheers!
- Marcelo

Actions #3

Updated by Mathias Bolt Lesniak 8 months ago

Cool! I get you. 👍

Actions

Also available in: Atom PDF