1
视频正在上传,但显示0bytes时,我检查的网络数据显示为无网络数据。从ios上传视频到服务器显示0bytes
NSString *str1=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"demo.mp4"];
NSLog(@"str1=%@",str1);
NSString *escapedUrlString = [str1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"escapedUrlString=%@",escapedUrlString);
NSURL *videoURL = [NSURL URLWithString:escapedUrlString];
NSLog(@"videoURL=%@",videoURL);
NSData *newdata = [NSData dataWithContentsOfFile:escapedUrlString];
webdata=[NSData dataWithData:newdata];
NSLog(@"webData = %@",webdata);
NSData *videoData = webdata;
NSString *urlString = @"http://192.168.1.92/Abdul/IOS/Chat/upload/upload_vid.php";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"file\"; filename=\".mp4\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:videoData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"returnString=== %@", returnString);
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
webdata1 =[[NSMutableData alloc]init];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[webdata1 appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"%@",error);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *responseString = [[NSString alloc]initWithData:webdata1 encoding:NSUTF8StringEncoding];
}
<?php
"Upload: " . $_FILES["file"]["name"] . "<br />";
"Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"]/1024) . " Kb<br />";
"Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
?>
好,谢谢,我会检查 – VyTcdc
不,我只为STR1为demo.mp4 – VyTcdc
的NSString * STR1 = [[[一个NSBundle越来越nill mainBundle] resourcePath] stringByAppendingPathComponent:@“demo.mp4”];使用这一行,并根据你的旧代码将它传递给含内容的文件 – Lion