we upload the files with webservice/upload.php. I don't know much about it yet too I've just talked with Dongsheng, we'll create soon a page about web service file handling in the developer documentation. Thank you for your question, I'll post a link once the doc is done.
we finished to write a web service file handling doc with some code examples: http://docs.moodle.org/dev/Web_services_files_handling
we'll integrate MDL-30459 soon. This small fix displays a much more comprehensive error message when the file name already exists in the "folder" (file area + path).
Also note that in this issue I wrote some option to support automatic rename when the "filename already exists" error occurs. However it seems that there is no real need for that, so I didn't commit. If someone thinks it's actually useful, write a new issue with a link to MDL-30459 and I'll commit it.