Fixes open file leak when a path is sent instead of an I/O stream

upload_photo does not properly close out files leading to a open file leak.
When an I/O stream is passed we probably don't want to close the file as the sender may still want it open, but when a file path is sent we should be closing out the file