Did you ever solve this problem? If so, could please share the code?
I figured it out, but it's a little bit tricky and I'm not sure if I did it the right way, but it works.
This method is not finished, it's just an example to add an uploaded file as a primary of a WTDocument. If already a primary exists it need to be deleted first. So it will only work for a WTDocument with no file attached.