First of all you should check if you have enough free space in user's account:
function long getFreeSpace(String login, String password);
(returned value - free space in bytes)
And what is upload limit for user (per file):
function long getMaxFileSize(String login, String password);
(returned value - maximum file size in bytes)
Please, check if target file corresponds the mentioned conditions, if it does, then:
function String createUploadSessionKey(String login, String password, long dirID);
Set '-1' as DirId parameter. In this case file will be uploaded to the root directory.
Or read full API description to learn how to browse user's directory for subdirectories' ids.
Return session key if everything is ok and empty or null string if you can't upload to the specified dir.
function int getNewFileDataCenter(String login, String password);
If returned datacenter is less or equal then 0 - something goes wrong.
Then get URL for upload using session and datacenter:
function String getUploadFormUrl(int dataCenterID, String sessionKey);
Returned string is only valid if it starts with http, otherwise, you can't upload file;
To reserve fileId for yor upload call function:
function long uploadStartFile(String login, String password, long dirID, String name, long fullSize);
Again, fileId can be only positive.
Then use received URL and fileId to upload by executing POST query multipart/form-data with fields.
Attach the file to the query as a parameter FilePart.
Where last parameter is file md5 digest. If the file is successfully uploaded - function returns null or empty line, if not - you will get an error message. If the file was uploaded by parts, this function unites them into one.
You are done!