永发信息网

iOS 江湖救急!!!怎样将音频文件上传到服务器

答案:1  悬赏:70  手机版
解决时间 2021-11-28 11:51
  • 提问者网友:龅牙恐龙妹
  • 2021-11-27 16:59
iOS 江湖救急!!!怎样将音频文件上传到服务器
最佳答案
  • 五星知识达人网友:佘樂
  • 2021-11-27 17:56
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 二进制流
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯