我正在使用 YouTube 可恢复上传:https ://developers.google.com/youtube/2.0/developers_guide_protocol_resumable_uploads#Sending_a_Resumable_Upload_API_Request
我使用 ASIHttpRequest 上传视频。对于直接上传,我可以使用这种方法。
- (void)appendPostDataFromFile:(NSString *)file
但是对于简历上传,我无法从整个视频文件中附加帖子数据。也许我可以写一个这样的方法:
- (void)appendPostDataFromFile:(NSString *)file offset:(long long)offset
但我不知道如何使它工作。任何帮助将不胜感激!这是来自 ASIHttpRequest 的代码:
- (void)appendPostDataFromFile:(NSString *)file
{
[self setupPostBody];
NSInputStream *stream = [[[NSInputStream alloc] initWithFileAtPath:file] autorelease];
[stream open];
NSUInteger bytesRead;
while ( !_isTryCanceled && [stream hasBytesAvailable] ) {
unsigned char buffer[1024*256];
bytesRead = [stream read:buffer maxLength:sizeof(buffer)];
if (bytesRead == 0) {
break;
}
if ([self shouldStreamPostDataFromDisk]) {
[[self postBodyWriteStream] write:buffer maxLength:bytesRead];
} else {
[[self postBody] appendData:[NSData dataWithBytes:buffer length:bytesRead]];
}
}
[stream close];
}
如上面的代码所示,如果我能得到一个可搜索的 NSInputStream,问题就解决了。有可能这样做吗?