Re: Uploading image via HTTP POST
Re: Uploading image via HTTP POST
- Subject: Re: Uploading image via HTTP POST
- From: Jens Alfke <email@hidden>
- Date: Thu, 21 Jan 2010 13:32:07 -0800
On Jan 21, 2010, at 8:39 AM, Daniel Meachum wrote:
> [[NSString alloc] initWithData:imageData encoding:NSUTF8StringEncoding]];
That's not going to work. Not all series of bytes are valid UTF-8, and in non-textual data like an image you're practically guaranteed to run into illegal UTF-8 sequences pretty quickly. The result will be a nil NSString.
If you want a string encoding that supports arbitrary byte values, try NSWindowsCP1252StringEncoding, which is the default encoding used on Windows. (It's a superset of ISO-8859 that includes encodings for 80-9F.)
You also haven't done any URL-encoding of the resulting string. Call stringByAddingPercentEscapesUsingEncoding: on the resulting string, but use NSWindowsCP1252StringEncoding as the encoding parameter (or whatever other 8-bit encoding you used.)
—Jens
PS: Off-topic, I can't believe the Tumblr engineers invented a protocol that's going to almost triple the size of the image data. It's not REST, or even the normal way that HTTP forms upload file attachments. Sigh.
_______________________________________________
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