File.create:after - change filename

Hi…
I change the filenames with the file.create:after hook in my config.
Now the change it self works like a chame, but if I use the type: files in my blueprints, the old name will be shown in the image-select-field.

This is my hook

'file.create:after' => function ($file) {
      $filename = $file->name();
      $filename = str_replace(' ', '-', $filename); // Replaces all spaces with hyphens.
      $filename = str_replace('.', '-', $filename); // Replaces all spaces with hyphens.
      $count = $file->files()->count() + 1; 
      $filename = substr($filename, 0, 30). '_' . $count;
      $file->changeName( $filename );
    }

where is my mistake?

What do you mean by type: files, a files field that stores the selected files? I wonder why that should happen when using the file.create:after hook though, unless you save the content before the renaming actually happens.

But yes, in other cases where the filename is changed after the filename has been stored somewhere, it will not be updated automatically in all places.

This is my blueprint for the file-selection or upload:
asset:
label: Image
type: files
multiple: false
query: site.find(“mm_images”).images.add(site.find(“mm_images”).children.images)
uploads:
parent: site.find(“mm_images”)
template: image
required: true
info: “{{ file.parent.title }}”

Can I do something to update this?

As long as we don’t have autoids for files, you would have to go through all pages and update them

Does the old filename really get stored in the content file with this hook? As long as you don’t save, it won’t, but I wonder if you run into some sort of race condition if you hit the save button to quickly.