refactor to support calling from servlet with file upload