Add normalize callback to pre-process files before processing#139
Add normalize callback to pre-process files before processing#139timfjord wants to merge 1 commit intoelixir-waffle:masterfrom
normalize callback to pre-process files before processing#139Conversation
|
Would it be possible to pass the renamed File struct to the upload |> File.new() |> Map.put(:file_name, "normalized") |> then(&Uploader.store({&1, current_user})) |
|
As per the current implementation, after normalisation, we pass whatever the So if I understand the question correctly, we do pass the renamed |
|
@timfjord I meant, can you just call the normalize function before calling waffle? ex: User uploads a file and you can call the normalize to change the file name before passing the file struct to Waffle |
|
Yeah, it is possible, but it makes the overall experience a bit inconsistent because there is no way to guarantee that the final file will have a unique name. That's why it would be nice to have this normalisation option built into Waffle. |
Introduces an optional
normalize/1callback to allow transforming/normalising the file after validation and before version processing/storage.This enables use-cases like renaming files(generating unique file names) or fixing metadata in a centralised, explicit step.
The idea of this PR was born when I was looking for a way to generate unique file names for uploaded files.
There is the
filename/2function, but it is for runtime filename calculation and heavily relies on the scope, and I was looking for something that would rename the file before even processing the versions.