POSIX error 12 (“Cannot allocate memory”) while uploading files from an iPhone

前端 未结 3 1408
长情又很酷
长情又很酷 2021-02-08 15:59

I\'m working on an iPhone application that involves uploading full photos from the camera (generally between 1.5 to 2.0 MB each) as well as their thumbnails (much smaller) to Am

3条回答
  •  广开言路
    2021-02-08 16:17

    The key to getting around this issue is to upload the file using a stream. When using NSMutableURLRequest, this can be accomplished using something similar to the following:

    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPBodyStream:[NSInputStream inputStreamWithFileAtPath:filePath]];
    

    When using ASIHTTPRequest, streaming a file is accomplished with this:

    ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:url];
    [request setPostBodyFilePath:filePath];
    rRequest.shouldStreamPostDataFromDisk = YES;
    

提交回复
热议问题