将数据上传到服务器iPhone [英] Upload Data To Server IPhone

查看:282
本文介绍了将数据上传到服务器iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个iPhone应用程序,允许用户在该应用程序中拍照并保存照片.此外,如果输入了诸如标题",位置"和其他信息"之类的数据,则仅允许用户将图像上传到服务器.

I want to develop an iPhone app that allows the User to take and save a photo within the app. Furthermore the user only is allowed to upload the image to server if data like "title", "location" and "additional information" is entered.

如果这样做,则应将图像和所属数据上传到我的Web服务器.

If done so, the image and the belonging data should be uploaded to my webserver.

我已经构建了一个从服务器检索数据的应用程序,因此建立连接将不是问题.

I have already build an app that retrieves data from a server, so building a connection will not be the problem.

由于我是Web服务器的新手,所以我的问题是上传带有自定义信息的图像的最佳方法是什么?

Since I'm new to web servers my question is what would be the best way to upload images combined with custom information?

什么是存储图像和所有物信息的好方法?我的猜测是该信息的MySQL数据库(标题,位置,其他信息,图像链接),图像又如何呢? 在哪里可以找到有关Web服务器上文件处理的信息?

What would be a good way to store the images and the belonging information? My guess would be a MySQL DB for the imformation (title, location, additional info, image link), and what about the images? Where can I read about file handling on web servers?

预先感谢

推荐答案

我建议将图像转换为base64表示形式,然后将其发布到Web服务调用中.

I would suggest converting the image to its base64 representation, and you can then post this in a web service call.

首先,使用以下命令将UIImage转换为NSData:

Firstly, convert the UIImage to NSData by using:

UIImage *img = [UIImage imageNamed:@"MyImage.png"];
NSData *imgData = UIImageJPEGRepresentation(img, 1.0);

然后,您可以使用由Matt Gallagher创建的一些有用的类将其转换为base64编码的字符串-请参见

You can then convert this to a base64 encoded string using some helpful classes created by Matt Gallagher - see this post here. In the code available to download, there is an NSData+Base64 class that will allow you to convert the data to a string:

NSString *imgBase64 = [imgData base64EncodedString];

一旦有了该字符串,就可以将其发布到服务器上,然后存储该字符串或对其进行解码,然后将其作为映像文件保存在服务器上.您应该能够找到使用所选技术来执行此操作的示例.

Once you have this string, you can post it to the server, and either store the string or decode it and save it on the server as an image file. You should be able to find an example of how to do this using your chosen technology.

这篇关于将数据上传到服务器iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆