mprythero's avatar

File And Folder Storage Recommendations

For storing materials, what is everyone’s standards for whether or not to place uploads in folders and their organization/naming standards?

If files are being renamed with the hash name or uuid, why wouldn’t it be okay to store the files in the root storage of the Storage/App folder?

I have over 100 models and I’m beginning to wonder if to make the upload process and file management processes more easy and standardized, if it wouldn’t be better to store everything except thumbnails in the root folder?

I’d appreciate any suggestions and recommendations.

0 likes
1 reply
Tippin's avatar

Depending on the Model or upload type, and model relations, I find nesting uploads in a similar hierarchy to the models relationships makes automating deleting processes much easier. I will use model IDs as the folder name, and they may have nested folders for sub models and their uploads. Example, Organization has many Project, and Project has many ProjectModel, which has many Render. I may setup directories as such:

- /organizations/{id}
    - avatars
    - documents
    - projects/{id}
        - avatars
        - models/{id}
            - obj
            - avatar
            - renders/{id}
                ...

So if I need to simply remove a specific render and its computed files, being the furthest nested item, I would have a helper method on the Render model that would go up the chain loading the org ID, project ID, model ID, and its own ID.

public function getStorageDirectory(): string
{
    $parent = $this->model->getStorageDirectory();

    return "$parent/renders/$this->id";
}

Storage::deleteDirectory($render->getStorageDirectory());

But if say, an entire organization was deleted. I can simply delete the top level directory for the organization without needing to run through every model/relationship and what files they may have.

public function getStorageDirectory(): string
{
    return "organizations/$this->id";
}

Storage::deleteDirectory($organization->getStorageDirectory());

Of course I can see you not wanting to nest too much, and your mileage may vary depending on your needs.

Please or to participate in this conversation.