Skip to content

Persist diskName per attachment in the JSON metadata (feature request) #37

Closed

Description

@PandaGuerrier

Is your feature request related to a problem?

I have several disks configured (e.g. s3 and local) and I'd like to spread uploaded photos across both of them — choosing the target disk dynamically at upload time rather than hardcoding a single disk per attribute via the @attachment({ disk: '...' }) decorator.
The problem is that the disk (or diskName) is not persisted in the JSON metadata stored in the database. As a result, once a file is written, the package has no record of which disk it actually lives on — it always resolves the disk from the decorator/config at read time. This makes it impossible to reliably serve, generate URLs for, or delete files when different rows of the same model are stored on different disks.

Describe the solution you'd like

Store the diskName per attachment inside the persisted JSON metadata, alongside the existing fields (name, extname, mimeType, size, etc.). On read (URL generation, deletion, etc.), the package should use the diskName from the stored metadata when present, and only fall back to the decorator/config disk when it's absent (for backward compatibility).

Describe alternatives you've considered

Hardcoding the disk per attribute via the decorator, but this prevents distributing files of the same model/attribute across multiple disks.

Additional context

This would enable use cases such as load-balancing storage across multiple backends, gradual migration between disks, or routing files to different disks based on runtime conditions.

Activity

  1. batosai commented on May 26, 2026

    @batosai
    Owner

    Hello,
    Could you tell me a bit more about how you are using (or planning to use) the package, both for storing and reading files?

    A few concrete usage examples would help me better understand your needs and the related constraints.

    Thanks 🙂

  2. PandaGuerrier commented on May 27, 2026

    @PandaGuerrier
    ContributorAuthor

    Hi,

    For example, I currently have an application in production that uses the 'fs' disk (local disk), and i added an new disk (cloudflare R2). I tried my best to migrate my photos, but I couldn't get it to work.

    Furthermore, when I pushed, I thought "it will automatically fetch the photo from the correct disk," but I was wrong, since you use the default disk.

    It would be great to be able to add the disk to the JSON payload stored in the database, so that when the URL is computed, it pulls from the correct disk.

  3. batosai commented on May 27, 2026

    @batosai
    Owner

    I understand. I’ll look to add this.

  4. batosai commented on May 28, 2026

    @batosai
    Owner

    Hello, I just created version 5.2.0-beta.2. Would you be able to help me test it?

    Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions