• 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
Re: Uploading image via HTTP POST
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Uploading image via HTTP POST
      • From: Daniel Meachum <email@hidden>
References: 
 >Uploading image via HTTP POST (From: Daniel Meachum <email@hidden>)

  • Prev by Date: Re: NSRulerView and inches
  • Next by Date: Re: NSHost and NSStream question
  • Previous by thread: Uploading image via HTTP POST
  • Next by thread: Re: Uploading image via HTTP POST
  • Index(es):
    • Date
    • Thread