Free file sharing
REST API SOAP API My Application

Upload

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:

Get session:

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.

Get datacenter:

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.

  1. resumableFileId (file ID received via previous method);
  2. resumableFirstByte (index of the first byte of current part. If the file is uploaded as single unit - then pass 0. If the file is divided into parts and is uploaded by parts - then pass index of the byte every part starts from).

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!

To search files on 4shared.com you should use the following url
http://search.4shared.com/network/searchXml.jsp

Parameters:

q - keyword

Example: q=funny cats

searchExtention - type of file (extension)

searchCategory - category

If you need extension just use searchExtention=mid. Remember, if you are using parameter searchExtention you should also use searchmode=3.

For searching in category use the following:

searchCategory=music/audio
searchCategory=video
searchCategory=photo
searchCategory=archive
searchCategory=office/books_office/document/books
searchCategory=program
searchCategory=web
searchCategory=mobile/mobile_palm
searchCategory=game

Example: use searchCategory=audio - if you are searching only for music.

Remember, if you are using parameter searchCategory you should also use searchmode=3.

sortType - type of sorting
1 - sort by downloads;
2 - sort by upload date;
3 - sort by size;
4 - sort by name;
sortOrder - sorting order(Ascending -1, Descending 1)
start - offset, is used for pagination

start value should be divisible by 10.

Usage example:

Response:

<search-result>
<query>somebody</query> - keyword
<total-files>24</total-files> - number of found files
<page-number>2</page-number> - page number
<pages-total>2</pages-total> - total amount of pages
<start>10</start> - offset
<files-per-page>10</files-per-page> - amount of files per page
<files-approx-count>24</files-approx-count> - approximate number
 of files (when amount of found files is more than 1,000). If amount of found files is less
 than 1,000 it equals to <total-files></total-files>
<result-files>
<file>
<name>somebody_to_shove.mid</name> - filename
<description/> - description
<downloads-count>8</downloads-count> - number of downloads
<upload-date-format>hh:mm dd-MM-yyyy</upload-date-format> - upload date format
<upload-date>04:19 19-05-2009</upload-date> - upload date
<url>http://www.4shared.com/audio/qVaKdItF/somebody_to_shove.htm</url> - download page url
<preview-url/> - preview url if exist
<flash-preview-url/>- flash preview url if exist
<user>wym</user> - username
<size>39 KB</size> - file size
</file>
<file>
...
</file>
</result-files>
</search-result>