Comments (4)
But in the after hook the original file should now be the actual file, shouldn't it? Or what else are you getting from $upload
?
The problem here is that our objects (like $file
) are immutable. So $file->update()
does not change the file object, but rather creates a new one with the modified content. These hook types are though only triggers. So what happens in the hook is also not passed back to the general script. And thus the script continues with the file object as it was passed into the hook. In the after hook it's less apparent as there it also writes the new content to the now existing content file, so on any new request that content gets actually read.
It's an issue of the immutability of our objects. We will have to look into if we can change the hooks to return something without being a huge breaking change. But if the after hook works for you in the meantime, I would go with that.
from kirby.
@silllli have you tried it with file.create:after
?
from kirby.
Yes, there it works. But in the after
hook the original file (passed as $upload
in the before
hook) is not available.
I could imagine that this is technically not possible (since we are in the before hook, so there is no actual file to update()
yet). But then why pass the $file
object to the hook?
Also, using the file.create:before
hook to save things like the filename to the file metadata was suggested in the forum in several thread so I expected it to work.
from kirby.
But in the after hook the original file should now be the actual file, shouldn't it? Or what else are you getting from
$upload
?
I am looking at ways to adjust the filename sanitization done by Kirby (mostly allowing uppercase letters). The Vue parts worked well, but adjusting the server-side sanitization is a lot more tricky. I found a solution that overwrites parts of the File
class in a plugin. That needs some code copying from and fiddling with the Kirby core—so it’s anything but future-proof.
I thought saving the original filename in the before
hook and then reapplying (with custom sanitization) it in the after
hook would be a cleaner and more future-proof way of handling this. In the after
hook, the filename was already sanitized and there is no way of accessing the original anymore.
Thank you for the quick replies!
from kirby.
Related Issues (20)
- [Panel] Email Dialog: Wrong translation key for title field
- Duplicated pages with copy files enabled still links to original files UUID HOT 1
- Page tables load very slow in 4.2 HOT 18
- Date field behaves weird when "display" MM/YYYY is used
- Search in panel shows old results when response times from server vary HOT 1
- Calendar not working with empty date field included in a structure field
- Unsaved changes bubble clipped and wrongly position on active/hovered tab HOT 1
- Files: don't run thumb processing if image smaller than the `create` dimensions HOT 2
- Hide page view options dropdown with no actionable options HOT 3
- Unexpected issue with sorting on setting the num prop when creating pages in code. HOT 4
- Failing Test for DateTest
- Non existing files throw error 500: the thumbnail configuration could not be found
- `k-table`: index column too narrow for high indexes HOT 1
- File browser doesn't start at current page HOT 5
- Filename sanitization rules are inconsistent HOT 1
- Filename sanitization rules are inconsistent HOT 6
- Throwing NotFoundException results in 500 error page HOT 1
- Strange behavior when clicking on tags field input
- Date picker not opening when clicking on date field in Panel HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kirby.