Refactor the whole uploads system

The uploads system now contains less coupling between backend and
frontend, and the manual and copy/pasted uploads now use the same
`uploadToBucket` function. This also makes it possible to do file
uploads over AJAX without having to use third party plugins.