Giter Club home page Giter Club logo

Comments (4)

distantnative avatar distantnative commented on June 24, 2024 1

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.

distantnative avatar distantnative commented on June 24, 2024

@silllli have you tried it with file.create:after?

from kirby.

silllli avatar silllli commented on June 24, 2024

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.

silllli avatar silllli commented on June 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.