

The only way that happens is if the upload behavior is still before the insert behavior.
What is happening is that the first time you test, it tries to upload the files, then sets the ID in a session, the next time you test, it uploads the file using the session from the first test, then inserts the record.
You must make sure the upload code comes after the insert code.


Well, since your using the ID, you really don't need to store the file name. but if you must, you would need to have an update behavior after the file upload.
reality is, using the ID for the file name is not a very simple process, especially on the insert.