Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Multipart POST using NSInputStream subclass



Hello,

I've been working on an NSInputStream subclass so I can POST a large file without loading the entire file into memory. I'm currently building the entire multipart/form-data body using NSMutableData, and passing this to -[NSMutableURLRequest setHTTPBody:]. The downside to this approach is that the entire HTTP body is resident in memory.

I noticed that the body of NSMutableURLRequest can alternately be set using setHTTPBodyStream:. I figured if I can subclass NSInputStream, I could achieve my goal. According to the NSInputStream doc [1], a subclass needs to override three methods read:maxLength:, getBuffer:length:, and hasBytesAvailable.

I've done this, and from my unit tests, it seems that I'm doing everything correct. However, when I try to use my stream in an NSURLConnection, I get the following runtime error:

*** -[DDMultipartInputStream _scheduleInCFRunLoop:forMode:]: selector not recognized [self = 0x3062b0]

I found a message on the list from 2005 citing "problems with subclassing
NSInputStream that may prevent it from working":


<http://lists.apple.com/archives/macnetworkprog/2005/Jul/ msg00004.html>

Is this still the case? Do I have to go the temporary file route? Or am I just not subclassing NSInputStream correctly?

Thanks,

-Dave

[1]: http://developer.apple.com/documentation/Cocoa/Reference/ Foundation/Classes/NSInputStream_Class/Reference/Reference.html

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.