目前我从iOS设备获取视频文件的NSData。我需要将它保存在php服务器上。我在这里面临一点困惑,我是否需要从NSData创建一个视频,或者只是保存NSData就可以了。这里需要指导什么是正确的方法。
感谢。
答案 0 :(得分:0)
您只需要在某个位置上传该文件。请遵循以下代码。该视频应附带关键媒体'
if(is_uploaded_file($_FILES['media']['tmp_name']))
{
$uploaddir = realpath('./upload/video/');
$fname='';//give any file name to save with extension'
$uploadfile = $uploaddir ."/". $fname;
if (move_uploaded_file($_FILES['media']['tmp_name'], $uploadfile)) {
$media = 'upload/video/'.$fname;
}
}
答案 1 :(得分:0)
这对你有帮助
NSString *videoURL = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mov"];
NSData *videoData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath: videoURL]];
AFHTTPClient *httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://www.domain.com"]];
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/videoupload.php" parameters:nil constructingBodyWithBlock:^(id <AFMultipartFormData>formData)
{
[formData appendPartWithFileData:videoData name:@"file" fileName:@"video.mov" mimeType:@"video/quicktime"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest: request];
[operation setUploadProgressBlock:^(NSInteger bytesWritten,long long totalBytesWritten,long long totalBytesExpectedToWrite)
{
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {NSLog(@"Video Uploaded Successfully");}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {NSLog(@"Error : %@", operation.responseString);}];
[operation start]