streamed HTTP POSTs problem
streamed HTTP POSTs problem
- Subject: streamed HTTP POSTs problem
- From: Gary Fielke <email@hidden>
- Date: Fri, 8 May 2009 10:58:39 +0930
I'm attempting to use CFStreamCreateBoundPair along with
CFReadStreamCreateForStreamedHTTPRequest to perform POST file uploads
with form field data.
Previously I have used a temporary file (containing the field data and
contents of the file to be uploaded) and used
CFReadStreamCreateWithFile to provide the streamed data for
CFReadStreamCreateForStreamedHTTPRequest. This worked fine but I'd
like to move away from the temp file idea.
I have seen other messages related to exactly this task which were a
great help but some where along the line I've tripped up. Here's my
setup:
1) create request and field data
2) create file read stream using CFReadStreamCreateWithFile using the
url of the file to be uploaded. No client set nor scheduled on run
loop. Open stream.
3) create bound read and write stream pair (bodyWriteStream,
bodyReadStream) using CFStreamCreateBoundPair (buffer size 4096).
Setup client, schedule and open the write stream (bodyWriteStream).
4) create httpRequest stream using
CFReadStreamCreateForStreamedHTTPRequest using the request and the
bodyReadStream from 3). Set client, schedule, and open httpRequest
stream. (The bodyReadStream apparently doesn't need to have a client
nor scheduled as the CFReadStreamCreateForStreamedHTTPRequest does this)
5) in the callback of the bodyWriteStream I do this for the
kCFStreamEventCanAcceptBytes event:
a) get field data (say length X) and write into a buffer of size 4096.
b) call CFWriteStreamWrite to write the X bytes of buffer to the
bodyWriteStream.
c) if all field data has been taken care of then start on the data of
the file to be uploaded using CFReadStreamRead on the file read stream
from point 2 above (this correctly reads file)
d) call CFWriteStreamWrite to write the buffer to the bodyWriteStream
This all seems to work fine up to the point where the
CFWriteStreamWrite has written 4096 bytes (the size of the buffer
specified in CFStreamCreateBoundPair) after which the next call to
CFWriteStreamWrite blocks.
Thanks for any help!
Gary
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden