Take picture with iPhone API and transfer it to a server

三世轮回 提交于 2019-12-04 20:37:01

问题


I have written an cocoa application to take a picture on the iPhone. I need to transfer the images taken to somewhere besides the iPhone namely another server. Does anyone know how I can accomplish this?

Thanks, Joe


回答1:


First get a server and figure out what kind of phone <---> server API you want to use. There are any number of ways it can work. A simple and common scheme is a REST API with photos being uploaded via HTTP POST.

The basic scheme would be something like:

  1. Take picture
  2. Convert to JPG (there's a function for this)
  3. Construct HTTP POST using the NSURL* classes
  4. Set JPG data as POST body (or one part of a mutipart form post)

Converting to base64 should not be necessary.

If you've never put together any kind of server API, there are any number of examples available. Most photo-sharing sites have public APIs which may be useful references.




回答2:


By far the easiest way is to use an HTTP POST. Take a look at the "URL Loading System" in your documentation and then examine the related classes, particularly NSURLRequest.




回答3:


As other people say, use HTTP POST. ASIHTTPRequest makes wrapping your POST up simple. It also moves your upload to a background thread and gives your delegate progress updates.




回答4:


You could always convert the image data to a base 64 string and POST it to a php (or other) script on the target server.



来源:https://stackoverflow.com/questions/699529/take-picture-with-iphone-api-and-transfer-it-to-a-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!