Before saving a node how to get the file path
Check out hook_file_presave() function.

You might have to additionally rename/move the file after it has been uploaded.

See also this thread and check the File (Field) Paths module as it might have already the functionality you need.