Saving uploaded files by tenant in multitenantcy

I want to save uploaded files in separate folder for each tenant. How can I do this.



You need to extend the fileDescriptor first:

It will look like as follows:

@Entity(name = "app$ExtFileDescriptor")
public class ExtFileDescriptor extends FileDescriptor  implements HasTenant {
    private static final long serialVersionUID = 3116325090574199150L;

    @Column(name = "TENANT_ID")
    protected String tenantId;

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;

    public String getTenantId() {
        return tenantId;

Then use the extFileDescriptor to create the entity where you will save the file to.

Thanks @mortozakhan.

This part I have already completed but having doubts about - “how to give folder location” or cuba will automatically save the file to tenant folder in default file saving folder.
I will try to check.

Thanks again.


Any more suggestion?


That worked for me. If it doesn’t work for you, it will be good if you can share details.

In order to use upload in a multi-tenant app, I implemented this solution on cuba 7.1 and multitenancy addon 1.4.0 and it worked fine.

I migrated to cuba 7.2.4 and multitenancy addon 2.0.1 and my button “upload” in back in “disabled” state.

Could you give an update on the solution with cuba 7.2 and multitenancy addon 2.0.1