<p>Not the "best" solution but if you really want to "disable" it you are free to overwrite the class via Dependency Injection and Service Locators.</p>

<p>You can overwrite the service with your custom one that extends Crafts service and "remove" the function </p>

<pre><code>Craft::$container-&gt;set('craft\services\Assets', [
    'class' =&gt; 'prefix\namespace\services\MyCustomAwesomeAssetService'
]);
</code></pre>

<p>Since this function is only really needed in the <code>AssetLocationValidator</code> you can as well replace it with your custom validation</p>

CC BY-SA 4.0
2018-05-10T21:57:27.490Z
thx, very nice workaround!
Visky Máté
CC BY-SA 4.0
2018-05-10T18:20:52.247Z
2018-05-10T18:20:52.247Z
Robin Schambach
<p>I have issue with the following code:</p>

<pre><code>public function getNameReplacementInFolder(string $originalFilename, int $folderId): string
{
    $folder = $this-&gt;getFolderById($folderId);

    if (!$folder) {
        throw new InvalidArgumentException('Invalid folder ID: '.$folderId);
    }

    $volume = $folder-&gt;getVolume();
    $fileList = $volume-&gt;getFileList((string)$folder-&gt;path, false);
</code></pre>

<p>The problem if I am using an external filesystem the getFileList is a very heavy API call for the external filesystem. It would be much easier to check the filename in the Asset database, than to check it on the filesystem.</p>

<p>Is there any way to avoid this call? Also if the flysystem driver is poorly written it could stuck in case of huge files or folders.</p>

<p>I badly need solution for disable this call - we can take care the indivudual file nameing, or to tweak it or change it for the database call</p>

<p>Thank you for your help</p>

<assets>
Issue with validator getNameReplacementInFolder
# Issue with validator getNameReplacementInFolder

(Asked by: username_0 on 2018-04-11)

I have issue with the following code:
public function getNameReplacementInFolder(string $originalFilename, int $folderId): string
{
    $folder = $this->getFolderById($folderId);

    if (!$folder) {
        throw new InvalidArgumentException('Invalid folder ID: '.$folderId);
    }

    $volume = $folder->getVolume();
    $fileList = $volume->getFileList((string)$folder->path, false);

The problem if I am using an external filesystem the getFileList is a very heavy API call for the external filesystem. It would be much easier to check the filename in the Asset database, than to check it on the filesystem.
Is there any way to avoid this call? Also if the flysystem driver is poorly written it could stuck in case of huge files or folders.
I badly need solution for disable this call - we can take care the indivudual file nameing, or to tweak it or change it for the database call
Thank you for your help

**Tags:** assets


---

## 1 answers

### Answer by username_1 on 2018-05-10. Score: 2 | Accepted answer

Not the "best" solution but if you really want to "disable" it you are free to overwrite the class via Dependency Injection and Service Locators.
You can overwrite the service with your custom one that extends Crafts service and "remove" the function 
Craft::$container->set('craft\services\Assets', [
    'class' => 'prefix\namespace\services\MyCustomAwesomeAssetService'
]);

Since this function is only really needed in the AssetLocationValidator you can as well replace it with your custom validation

> **Comments:**
> **username_0**: thx, very nice workaround!  

---

