Handle uploading empty files

This is a bug fix for uploading empty files. The upload will fail without this, because it doesn't create the encoded file but tries to decode it.

It doesn't really require #103, but I built it on top of that because it made test cases easier to write. So I'd make a decision about that PR first, and then I can rebase this PR if necessary.