【发布时间】:2015-12-22 21:34:09
【问题描述】:
我正在制作一个应用程序,它将数据从眼镜传输到服务器进行广播。 到现在为止,我可以将数据从眼镜下载到我的 iPhone 文档目录。 现在我想将下载的数据上传到我的服务器,以便我们可以将这些数据广播给我们的用户。
我的 iPhone 和眼镜在 WiFi 的帮助下相互连接,我正在尝试通过蜂窝网络上传下载的数据。
所以基本上我的概念是从眼镜下载数据并将其上传到服务器。
我尝试将我的 iPhone 作为服务器,以便我的后端团队可以从我的 iPhone 下载数据。
我在这个方法中取得了成功,但问题是对于这个过程,客户端和服务器应该在同一个私有 ip 网络上。
所以现在我们只剩下一种方法,即从眼镜下载 TS 夹头,同时将 TS 文件上传到我们的服务器进行广播。
我正在使用NFNetworking 从眼镜“TS 文件”下载视频夹头,但无法将夹头上传到我的服务器。
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://xxx.xx.xx.x/abc/trunk/WebServices/app/webroot/xyz"]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request] ;
operation.outputStream = [NSOutputStream outputStreamWithURL:[NSURL URLWithString:@"http://abc.aa.a.a/xyz/trunk/WebServices/app/webroot/img/glasses/test/demo.ts"] append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// NSLog(@"Successfully downloaded file to %@", path);
// NSLog(@"download finished!");
if(_delegate && [_delegate respondsToSelector:@selector(ZBTM3U8SegmentDownloaderFinishDownload:)])
{
[_delegate ZBTM3U8SegmentDownloaderFinishDownload:self];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// NSLog(@"Error: %@", error);
}];
[operation start];
进入成功状态,但数据未上传到服务器 服务器文件夹显示为空。
- (void)postVideoOnServer {
NSDictionary *requestDict = @{ @"uniqueToken":@"101", @"user_id":@"102",};
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:_tsFileName];
NSData *selectedVideo = [NSData dataWithContentsOfFile:path];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPRequestOperation *operation = [manager POST:@"http://xxx.x.x.xx/myi/public_html/WebServices/broad/axy" parameters:requestDict constructingBodyWithBlock: ^(id <AFMultipartFormData> formData) {
[formData appendPartWithFileData:selectedVideo name:@"file" fileName:@"filename.ts" mimeType:@"video/quicktime"];
} success: ^(AFHTTPRequestOperation *operation, id responseObject)
{
NSInteger statusCode = operation.response.statusCode;
NSLog(@"Status Code ::%d", statusCode);
NSLog(@"Response ::%@", responseObject);
[self handleVideoServiceResponse:responseObject];
}
failure : ^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error: %@ %@", operation.responseString, error);
}];
[operation start];
}
它总是返回请求超时错误。
提前致谢。
【问题讨论】:
-
所以如果你已经成功下载NSLog(@"成功下载文件到%@", path);那么为什么你的提问帖子显示下载代码。你不应该发布造成问题的上传方法。你也可以播放 ts 格式的视频吗?
-
你确定 NSData *selectedVideo 不是 nil 吗?我怀疑你也模仿类型?只是一个建议尝试使用 MIME: video/MP2T
-
NSData 不是 nil ,我正在从本地存储中获取数据。
-
是否有任何可能的方式将下载的数据上传到另一台服务器而不将其保存到本地存储。以加快处理速度。
-
您现在可以在服务器上上传数据了吗?
标签: ios iphone upload streaming afnetworking