0
我想上傳示例視頻文件到服務器上我按下按鈕。我使用下面的代碼。上傳示例視頻文件到服務器的問題
-(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"];
NSMutableData *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=\"videofile.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];
UIAlertView *statusAlert = [[UIAlertView alloc]initWithTitle:nil message:(NSString *)returnString delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
[statusAlert show];
感謝您的回覆。我修改了上面的代碼,我收到警告和應用程序終止。我是初學iphone應用程序,所以我感到困惑。請幫助我。 – sny 2010-11-22 08:14:18
嗨,我沒有看到你之前加載的數據,你是加載字符串作爲數據,而不是視頻數據,我已經糾正了上述代碼,現在嘗試.. – Sanniv 2010-11-22 09:10:12
是的,現在我糾正了,但它給上傳video.is代碼足以使uplooding示例視頻。我想從服務器mesg應該像上傳成功,我不喜歡那樣。 – sny 2010-11-22 09:34:15