What is the correct way of sending large file through HTTP POST, without loading the whole file into ram?

前端 未结 3 1680
感情败类
感情败类 2021-02-01 08:45

I\'m currently working on an application for uploading large video files from the iPhone to a webservice through simple http post. As of right now, I build an NSURLRequest and p

3条回答
  •  臣服心动
    2021-02-01 09:30

    One way to do this is to use an asynchronous NSInputStream in concert with a file. When the asynchronous connection asks you to provide more data, you read in the data from a file. You have a few ways to do this:

    • UNIX/BSD interface. use open (or fopen), malloc, read, and create a NSData object from the malloced data

    • use the above with mmap() if you know it

    • use the Foundation class NSFileHandle APIs to do more or less the same using ObjectiveC

    You can read up on streams in the 'Stream Programming Guide'. If this doesn't work for you there are lots of open source projects that can upload files, for instance MKNetworkKit

提交回复
热议问题