• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSURLConnection & NSInputStream issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSURLConnection & NSInputStream issue


  • Subject: NSURLConnection & NSInputStream issue
  • From: David LeBer <email@hidden>
  • Date: Mon, 15 Dec 2008 16:45:50 -0500

Hello all,

I have a requirement where I need to send a chunked file (about 2MB at a time) to a server. Each chunk is embedded as a base64 encoded string in the body of an HTML POST request.

I'm working on a proof of concept dev spike and I've got this code which fails:

- (void) callUploadAssetChunk
{
NSString *contentString = [[NSString alloc] initWithFormat:@"contactInfoXML=%@&mediaValueID=%@&hash=%@&chunkIndex= %d&chunk=%@",
[self contactInfoXML],
[[self currentAsset] mediaValueId],
[[[self currentAsset] currentUploadChunk] chunkHash],
[[[self currentAsset] currentUploadChunk] chunkIndex],
[[[self currentAsset] currentUploadChunk] encodedChunkData]];


NSData *contentData = [ NSData dataWithBytes: [ contentString UTF8String ] length: [ contentString length ] ];

NSString *path = [NSString stringWithFormat:@"%@/ UploadAssetChunk", kWebMethodsFull];

NSURL *url = [[NSURL alloc] initWithScheme:kURLScheme host: [uploadUrl stringValue] path:path];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

   [request setHTTPMethod: @"POST"];

NSInputStream *dataStream = [NSInputStream inputStreamWithData:contentData];

   [request setHTTPBodyStream:dataStream];

[self setChunkUploadConnection:[NSURLConnection connectionWithRequest:request delegate:self]];

   [url release];
   [request release];
}

In looking at the wire, I see the HTTP headers go by, but there is no body content. If I bypass the NSInputStream with the NSData and replace:

[request setHTTPBodyStream:dataStream];

With:

[request setHTTPBody:contentData];

Everything works fine.

I am testing with an NSInputStream because I'd like to be able to query it to get an upload progress for the user. So, it looks like I am either misreading the NSURL* API (possible) or missing something obvious in creating the NSInputStream (also possible). If anyone has any suggestions, I'd love to hear it.

It is so frustratingly close. If it weren't for those darn needy users and their dislike of not knowing what was going on, I'd be done now :-)

;david

--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site: 	http://codeferous.com
blog: 	http://davidleber.net
profile:	http://www.linkedin.com/in/davidleber
twitter:	http://twitter.com/rebeld
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org




;david

--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site: 	http://codeferous.com
blog: 	http://davidleber.net
profile:	http://www.linkedin.com/in/davidleber
twitter:	http://twitter.com/rebeld
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Solved - sorta (Was: NSURLConnection & NSInputStream issue)
      • From: David LeBer <email@hidden>
  • Prev by Date: Re: What is the default type for an integer literal (as relates to its use in NSLog)?
  • Next by Date: Double KVO notification
  • Previous by thread: Re: What is the default type for an integer literal (as relates to its use in NSLog)?
  • Next by thread: Solved - sorta (Was: NSURLConnection & NSInputStream issue)
  • Index(es):
    • Date
    • Thread