将图像和文本上传到服务器 [英] upload images and texts to server

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

问题描述

我已经完成了一些编码,并且在上传时发现了一些中断.

I have already gone through some codings, and I found some interrupts in uploading.

我想使用ASIHTTPRequest将六个图像上载到服务器文件夹,并将一些文本上载到服务器数据库. 请提供任何示例代码,感谢您花时间回答我的问题.

I want to upload six images to a server folder and some text to server database using ASIHTTPRequest. Any sample code please, thanks for spending time for my question.

推荐答案

要将图像上传到服务器,您需要以下代码:

For uploading images to the server you need the following code:

NSURL *url = [NSURL URLWithString:@"http://www.xyz.com/UploadImage.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
request.requestMethod = @"POST";
NSString *fileName = @"iphone.jpg";
[request addPostValue:fileName forKey:@"name"];

// Upload an image
UIImage *img = [UIImage imageNamed:fileName];
NSData *imageData = UIImageJPEGRepresentation(img, 90);
[request setData:imageData withFileName:fileName andContentType:@"image/jpeg" forKey:@"image"];
[request setDelegate:self]; 
[request startAsynchronous];

要将文本发送到服务器,您只需要使用POST方法添加文本即可,例如:

For sending text to the server, you just need to append the text with the POST method like:

[request appendPostData:[@"This is my data" dataUsingEncoding:NSUTF8StringEncoding]];

干杯!

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

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