So far, that is, iPhone SDK 2.2, Apple still does not provide a file transfer solution for developers. If an application needs to provide users with the ability to upload files to the iPhone, it will use one of the following methods:
- Download from the Internet through a link.
- Provides a client for uploading through its own protocol.
- Supports FTP transfer protocol.
- Start an HTTP service on the iPhone and upload it through a browser.
- Further than the previous one, WebDAV is supported on HTTP and uploaded through Protocol modification.
These methods have their own advantages and disadvantages. Although the development in the first two methods is relatively simple, the user operations are not convenient, and fewer methods are used. Using FTP requires additional client software On some systems, which is not convenient. The WebDAV Method is now popular, and both air sharing and discover adopt this method.
When using the iPhone ichm, you also need to provide the file upload function. I chose the fourth solution, that is, to provide an HTTP service for uploading through a browser. Although this scheme cannot be directly mounted to a file system like WebDAV in some systems, it does not need to install additional clients for almost all systems with browsers, it is much easier to implement than WebDAV.
In the selection of HTTP server, you can porting existing mature products, but for such applications, Apache or Lighttpd solutions are too complex, in fact, just a very simple service. Finally, we found the cocoahttpserver, which is an open-source project by deusty designs. It supports asynchronous socket, IPv4 and IPv6, HTTP Authentication and TLS encryption, which is small and exquisite. Except for the get method, all others can be said to have and none of them are.
I have extended cocoahttpserver, and first realized the support for multipart POST. In the design of the file transfer function, I use files as a resource and use the rest method:
Method |
Function |
Get |
File List, File Download |
Post |
Upload new files |
Delete |
File Deletion |
This design is clear from the interface and implementation perspectives.
After ichm 1.0 was released, it was relatively stable after ichm 1.0.1. Now I will transfer this part of the code Open Source:
Cocoa Web Resource Project
The main functions are as follows:
- You can use a browser to upload files to the iPhone/iPod Touch, and download and delete files.
- Memory is optimized and supports uploading large files.
- Customizable web interface.
- Web interfaces support mainstream browsers such as IE, Safari, and Firefox.
- Restful API.
I hope it will help iPhone developers.