On 07/03/2013, at 3:11 AM, Jesse Tayler wrote: > > On Mar 6, 2013, at 7:03 AM, Paul Yu <[email protected]> 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 protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
