• 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: ERAttachment and ERRest
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ERAttachment and ERRest


  • Subject: Re: ERAttachment and ERRest
  • From: Matthew Ness <email@hidden>
  • Date: Thu, 07 Mar 2013 09:56:34 +1100


On 07/03/2013, at 3:11 AM, Jesse Tayler wrote:


On Mar 6, 2013, at 7:03 AM, Paul Yu <email@hidden> wrote:

Jesse

Can/would you share your solution on how you got your iOS image to post to the ERRest server and then how do you pass that back down?

Thanks.


I could try! I don't know if you want to be following after me ;-)

there. I made a smiley.

Some of what I'm doing seems disgusting, but maybe I was cool to have figured it out.

You do have to setup some headers and things - or I did I guess.

On my server, I have a relationship from Person to an ERAttachment called "poster"

so in iOS I call that URL (blahblah/Person/999/poster.bplist or something) then you send it wrapped binary image data and some headers.

I had to pad the data to form a proper boundary format for multi-part handling like so:



   [urlRequest addValue:@"image/png" forHTTPHeaderField:@"mimetype"];
   [urlRequest addValue:@"image/png" forHTTPHeaderField:@"Mime-Type"];

   [urlRequest addValue:@"photo.png" forHTTPHeaderField:@"filename"];

   NSString *boundary = @"---------------------------14737809831466499882746641449";
   NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
   [urlRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];

   NSMutableData *body = [NSMutableData data];
   [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

   //Image
   [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"filMyFile\"; filename=\"%@\"\r\n", @"poster.png"] dataUsingEncoding:NSUTF8StringEncoding]];
   [body appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
   [body appendData:scaledImageData];
   [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

   [urlRequest setHTTPBody:body];



And then I push all that to the server.

does that help?

oh, passing back down is as easy as anything else - I get my images from Amazon S3 like any web image.

let me know if you need help on that.



That's pretty similar to what we do, although in a different language, and we push multiple files into the one request using content-disposition and boundaries.

Aside: if you are not doing any processing of the files at the application tier, and are using AWS S3, you could directly upload the files to your S3 bucket(s) using CORS:

http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html

Cheers,

-- 
Matt.

http://logicsquad.net/


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: ERAttachment and ERRest (From: Jesse Tayler <email@hidden>)

  • Prev by Date: Re: simple survey for PostgreSQL
  • Next by Date: Re: simple survey for PostgreSQL
  • Previous by thread: Re: ERAttachment and ERRest
  • Next by thread: postgres jdbc driver
  • Index(es):
    • Date
    • Thread