Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Pass original upload filename into AssetUploaded event #11423

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from

Conversation

daun
Copy link
Contributor

@daun daun commented Feb 6, 2025

Suggested change

Pass the original filename into the AssetUploaded and AssetReuploaded events.

Use case

This will allow saving the original filename into the asset metadata from a custom listener. Mostly applicable to download buttons or zip features that benefit from keeping the original name including capitalization and any © marks.

{{ assets }}
  <a href="{{ url }}" download="{{ original_filename }}">Download</a>
{{ /assets }}
<a href="image--photographer.jpg" download="Image © Photographer.jpg">Download</a>
class OriginalFilenameSubscriber extends Subscriber
{
    protected $listeners = [
        AssetUploaded::class => 'saveOriginalFilename',
    ];

    public function saveOriginalFilename(AssetUploaded $event)
    {
        $event->asset->set('original_filename', $event->originalFilename);
        $event->asset->saveQuietly();
    }
}

Semver

  • Technically, this is only adding an argument, so it should be non-breaking
  • However, any addons/consumers "faking" those Events will get errors from the now-missing required argument

Alternatives considered

  • Just save the original filename into the asset meta on creation? Wouldn't require updates to the event signatures
  • Make filename sanitization hookable and somehow match the change to the asset? Sounds a bit hacky

Closes

Closes statamic/ideas#1282

@jasonvarga
Copy link
Member

jasonvarga commented Feb 6, 2025

Can't you already do $asset->getOriginal('path')? Sorry I misunderstood what this PR was actually doing. 🤐

@daun
Copy link
Contributor Author

daun commented Feb 6, 2025

The asset is created with the filename already sanitized, so unfortunately no :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remember the original filename of uploaded assets
2 participants