嘿朋友们,我即将将视频从 iphone 发送到我的服务器,但由于某种原因,我的服务器在将文件上传到文件目录时出现问题。我知道我错过了一些简单的人可以指出的东西。
NSMutableDictionary* params = nil;
NSString* command = nil;
NSData* videoPackage = [NSData dataWithContentsOfURL:self.vidURL];
NSData* imagePackage = UIImageJPEGRepresentation([UIImage imageNamed:@"videoShareDone.png"], 70);
command = @"videoUpload";
params = [NSMutableDictionary dictionaryWithObjectsAndKeys:command, @"command",[_apManager uniqueID], @"unique_id",_apManager.userID, @"parent_id",@"blah",@"video",[NSDate date],@"ts_created", captionText.text,@"videoCaption",[ShareVideoController base64forData:imagePackage],@"coverImage", nil];
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"Str33trider/" parameters:params constructingBodyWithBlock: ^(id <AFMultipartFormData>formData)
{
[formData appendPartWithFileData:videoPackage name:@"uploadVideo" fileName:@"testthis.MOV" mimeType:@"video/mov"];
}];
request.timeoutInterval = 10.0;
AFJSONRequestOperation *operation = [[[AFJSONRequestOperation alloc] initWithRequest:request] autorelease];
[operation setUploadProgressBlock:^(NSInteger bytesWritten,long long totalBytesWritten,long long totalBytesExpectedToWrite)
{
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
id JSON = [(AFJSONRequestOperation *)operation responseJSON];
NSLog(@"responseString == %@, json code:%d", operation.responseString, [[[JSON valueForKeyPath:@"status"] valueForKeyPath:@"code"] intValue]);
if ([[[JSON valueForKeyPath:@"status"] valueForKeyPath:@"code"] intValue]==200)
{
NSLog(@"worked");
}
else
{
NSLog(@"failed");
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"error: %@", operation.responseString);
}];
[operation start];
这是我的 PHP 代码
function ulVideo ($unique_id, $parent_id, $video, $ts_created, $videoCaption, $coverImage)
{
if(!empty($_FILES))
{
$target_path = '/Library/WebServer/Documents/Str33trider/userVideos/';
$target_path = $target_path . basename( $_FILES['uploadVideo'][$unique_id]);
if(move_uploaded_file($_FILES['uploadVideo'][$unique_id], $target_path))
{
echo "The file ". basename( $_FILES['uploadVideo'][$unique_id]).
" has been uploaded";
}
else
{
echo "There was an error uploading the file, please try again!";
}
}
}
我收到响应“上传文件时出错,请重试!”;