• 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: Jesse Tayler <email@hidden>
  • Date: Wed, 06 Mar 2013 11:11:13 -0500

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.



 _______________________________________________
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

  • Follow-Ups:
    • Re: ERAttachment and ERRest
      • From: Matthew Ness <email@hidden>
  • Prev by Date: Re: WebObjects 5.3.4 Frontbase question
  • Next by Date: postgres jdbc driver
  • Previous by thread: Re: REST PUT request creating related objects rather than just updating them
  • Next by thread: Re: ERAttachment and ERRest
  • Index(es):
    • Date
    • Thread