【发布时间】:2010-11-24 08:54:46
【问题描述】:
我正在尝试使用 HTTP 发布方法将 .3gp 视频文件从我的 iPhone 应用程序上传到我的服务器。我的项目资源中提供了 3gp 视频文件。为此,我使用以下代码,
-(IBAction)buttonAction
{
NSMutableURLRequest* post = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: @"http://115.111.27.206:8081/vblo/upload.jsp"]];
[post setHTTPMethod: @"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------358734318367435438734347"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[post addValue:contentType forHTTPHeaderField: @"Content-Type"];
body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"videofile\"; filename=\"video.3gp\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[[NSBundle mainBundle] pathForResource:@"video" ofType:@"3gp"]
dataUsingEncoding: NSASCIIStringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[post setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:post returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
// Just to show the response received from server in an alert...
UIAlertView *statusAlert = [[UIAlertView alloc]initWithTitle:nil message:(NSString *)returnString delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
[statusAlert show];
}
这段代码没有任何作用。
谁能指导我怎么了?
更新:
我从链接中看到了一个示例-> iphone.zcentric.com/page/2 正在使用“iphone.zcentric.com/test-upload.php”; PHP 上传,在我的代码中我使用 JSP "115.111.27.206:8081/vblo/upload.jsp";上传到我的服务器。这里有什么问题吗?
谢谢。
【问题讨论】:
-
我不建议同步发送视频文件,因为它们通常很大并且用户希望看到某种进度条。
标签: iphone