You could do have declare variable for input file field as #file & then only file change do call upload function to pass uploaded file to function.
#file
upload
Upload file