美文网首页
怎么样上传音频文件(NSData方法)

怎么样上传音频文件(NSData方法)

作者: 王欣12138 | 来源:发表于2016-06-25 09:26 被阅读385次

    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 二进制流

    相关文章

      网友评论

          本文标题:怎么样上传音频文件(NSData方法)

          本文链接:https://www.haomeiwen.com/subject/sycadttx.html