Callback after upload or ...?

I created an uploadfield to upload related files. For now the field is merely meant to upload related files. The files are collected in another view so the field value isn’t that important. My initial idea was to empty the field after the file is uploaded (and/or moved) to the right folder.

I create a field
$crud->setFieldUpload(‘pdfnaam’, ‘library’, $libraryPath);
to upload the files. I want them however to go to a folder that’s numbered with the primary key.
i tried:
$stateInfo = $crud->getStateInfo();
$customerId = $stateInfo->primaryKeyValue;

$librarypath."/".$customerId in the setFieldUpload, but I get an error. Obviously because in it’s initial state there is not yet a primaryKeyValue.

I tried moving the file in a CallbackAfterUpdate, but I get an error that moving/renaming isn’t available.
I also tried filtering the state but I can’t find a way to pass the value of the pr.Key.Val to the upload path.

So basically the Upload should go to $base_Url . $librarypath . $primaryKeyValue instead of $base_Url . $librarypath

Is there anyone who has a solution?
Thank you

hello , sir ,
did you fix the problem you have dealing with ?
if yes can you tell me the solution to your problem because I am dealing with the same when I am trying to
upload a file to a specific folder but when I define the set_field_upload with my path, the function uses the default path , not the folder that I have set…
can you help me?

Also, have you ever used the state=upload_file ;

I tried to understand…
Your folder doesn’t exist so how do you create it before ?
Example a folder named ‘Files’ and now you have a file with primary key “516” so you want that the file will be uploaded in ‘files/516/MyUploadedFile.pdf’ is that correct ?
If yes how do you create the 516 folder ?