FTP vs HTTP upload on iPhone

2019-07-06 21:06发布

In my iPhone application I need to upload images to a server. I don't worry much about security and stuffs, just need a fast and reliable method. I can embed my image data on the HTTP post request, or I can create a FTP connection to the server (using the SimpleFTPSample from Apple). The disadvantage of each method is: - HTTP: time out if image too big without way of resuming, and no way to know the upload progress (%)? - FTP: sometimes I got NSStreamEventErrorOccurred and don't know why (when tested on device, on simulator it works great. So maybe 3G errors?)

My question is, do you have any experience with this problem (upload image to server)? What method do you recommend? FTP, HTTP or other method? Thanks in advance.

5条回答
不美不萌又怎样
2楼-- · 2019-07-06 21:38

I finally continue to use HTTP, and use the following delegate method to track upload progress:

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite

totalBytesWritten / totalBytesExpectedToWrite gives me the upload percentage.

查看更多
三岁会撩人
3楼-- · 2019-07-06 21:40

A third option would be, if you control the destination server, is to create your own protocol to send data. That could get you the flexibility your desire at the cost of having to deal with the lower level features yourself.

查看更多
来,给爷笑一个
4楼-- · 2019-07-06 21:41

For one of my projects, I had the requirement to upload images to a web server from various mobile devices (IE: iPhone and Android devices). I created a Java Servlet that would accept an image through a POST request and save it to the server. There are also links to Objective-C (iPhone/iPad) and Java (Android) clients. The tutorial is here

查看更多
你好瞎i
5楼-- · 2019-07-06 21:44

The fact that many networks block FTP traffic would steer me towards HTTP POST.

查看更多
霸刀☆藐视天下
6楼-- · 2019-07-06 21:51

Fast, Easy & reliable: ASIHTTPRequest and you can track upload progress.

查看更多
登录 后发表回答