Fix tmp file being deleted after the request plus some cleanup and improved erroring for this situation