iOS 江湖救急!!!怎样将音频文件上传到服务器
展开全部
http上传 把文件以body形式上传到服务器 NSFileHandle* handler = [NSFileHandle fileHandleForReadingAtPath:_fileURL];
[handler seekToFileOffset:(unsigned long long)_range.location];
NSData* body = [handler readDataOfLength:_range.length];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
[request setValue:@"video/mp4" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d",body.length] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"no-cache" forHTTPHeaderField:@"Cache-Control"];
[request setHTTPBody:body];
然后服务器接收body 二进制流
[handler seekToFileOffset:(unsigned long long)_range.location];
NSData* body = [handler readDataOfLength:_range.length];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
[request setValue:@"video/mp4" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d",body.length] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"no-cache" forHTTPHeaderField:@"Cache-Control"];
[request setHTTPBody:body];
然后服务器接收body 二进制流
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询