-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Simple serializable temporary filesystem #91
base: 1.x
Are you sure you want to change the base?
Conversation
Thanks, I'd forgotten about this! Could you split this out into it's own PR? Regarding temporary files, this is sort of what I was envisioning:
I think we could have the same functionality in a new form type (#87) |
Sure, will do
I though about it and decided against it because we'd need to at least add validation logic into the value resolver (we don't want to store files we can easily discard by validation) and possibly some manipulators (although I think I have specifically omitted the |
True. I like the idea of adding constraints. Maybe we should auto-add the For what to do when the constraints fail? I think throwing a 422 (customizable) would be best. There are some PR's in Symfony core that are looking to add this feature to request parameters. ie: If you want to do something else like collect the validation errors and return. Thinking this would need to be done manually by either accepting a What I'm trying to avoid is a 1st party concept of a temporary file/filesystem. I'd like this to be just another filesystem. What I'm thinking for the attribute: public function __construct(
?string $path = null,
bool $image = false,
list<Constraint> $constraints = [],
?string $filesystem = null, // required if type hint is File/Image
Namer|string|null $namer = new Expression('{checksum}/{name}{ext}'), // used if type hint is File/Image
) {} The above is probably too much for one attribute so maybe we could split into |
Another thought I had about this: while I understand it's a waste of resources to save a file that's going to be discarded because it fails validation, it would make the validation of files consistent with other validators. Consider a text field that has a Also, consider a future enhancement, that allows users to upload files directly to an s3 bucket (on submit, the form sends the link to the file instead of the file itself). The file exists and will eventually be discarded after validation fails. This would be consistent with that. |
I have split this PR into two, for now without any changes. I have noticed that due to decoration of nodes my logic regarding temporary files is completely wrong here. I will work on it more tomorrow 👍 |
In this PR I have collected 2 different topics, but both are pretty straight forward.First of them is bringingValueResolver
fromdocument-library
and extended to supportPendingImage
. I think it needs no comment 😸Second one is a temporary file decorated filesystem. It's purpose is to store uploaded files with original filenames so that they can be serialized and moved to the final filesystem (with all the naming etc.) automatically via doctrine listeners. The implementation is simpler than I initially thought, but hopefully complete.
I am not really happy with
TemporaryFilesystem
name, but couldn't find any better. The idea is that upon validation ofPendingFile
/PendingImage
we can call$file->saveToTemporary($filesystem)
and store the result in session (or elsewhere, serialized) only to move to persistent filesystem when required - this part is exactly what's the most complicated in handling files in live components without this library.It is a proof of concept, I should add tests and a bit of docs, but for now I prefer to show you something and polish it when we have agreed direction for those.
This library already provides a purge filesystem command that could be ran via CRON to clean the temporary filesystem from old files.