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

New 'getDownloadFilename' method for extensibility #3504

Merged
merged 2 commits into from
Jan 11, 2024

Conversation

chrispage1
Copy link
Contributor

When downloading a file by utilising Responsable, the file naming at the point of download isn't very flexible.

I've added a method that allows extending the Media class, and in turn the download file name, rather than having to create my own download controller for a filament project I'm working on (for some reason in Filament the file names are by default obfuscated). I can then simply extend the functionality by overriding the method

    public function getDownloadFilename(): string
    {
        return $this->name . '.' . pathinfo($this->file_name, PATHINFO_EXTENSION);
    }

In addition I've utilised Symfony's HeaderUtils class (as Laravel does) to generate the disposition, ensuring it's sanitised and always correctly formatted.

Thanks!

Added Symfony HeaderUtils to create content disposition
@freekmurze
Copy link
Member

Seems like the testsuite is failing because of these changes. Could you take a look at that?

@chrispage1
Copy link
Contributor Author

Seems like the testsuite is failing because of these changes. Could you take a look at that?

Sure, its changed the disposition structure slightly, I'll reconsider that element 👍

@chrispage1
Copy link
Contributor Author

@freekmurze I've changed the way its being sanitised as it turns out the HeaderUtils is a bit too strict, e.g. 'my file name.png' would be converted to 'my-file-name.png' but there's no reason why a file name couldn't include spaces when downloading.

So instead escaping quotes and using ascii formatting.

Thanks!

@freekmurze freekmurze merged commit fded7c9 into spatie:main Jan 11, 2024
5 checks passed
@freekmurze
Copy link
Member

Thanks!

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.

None yet

2 participants