Fix upload dir and generate attachment metadata

Fixes #249