fix file descriptor leak

The file to be uploaded is opened, but not closed once the upload is completed.
If you upload multiple files with the same ConcurrentUploader all files remain open and you eventually run out of file descriptors
This adds a _cleanup function that gets called when work is done that closes the file
Remove trailing whitespace
Add unittest for #1323
Merge branch 'ksacry-patch-1' into develop

* ksacry-patch-1:
  Add unittest for #1323
  Remove trailing whitespace
  fix file descriptor leak