Fix multiple chunk document upload

Also includes an added test and extracting a method to a DAO. These can be separated from the pull request if there is any concern about them.