1

I have an app that can take pictures and the goal is to upload them to our .net server.

The developer maintaining the server has asked me to send each image as a byte array.

Is that something I can do with iOS and if so, how? Do I need to engage him with more questions about sending a byte array or is there a simpler method? I've made updates with the same developer's web services before but never sending an image (just text or json).

I showed him this thread and he is oblivious.

Community
  • 1
  • 1
kraftydevil
  • 5,144
  • 6
  • 43
  • 65
  • Well what kind of server is this? Are you meant to make HTTP posts, for example? Connect directly via your own protocol over TCP/IP? Send all the images over a single connection, or use one connection per image? – Jon Skeet Aug 29 '14 at 20:13
  • HTTP posts if we stick with what we've done before. Probably TCP/IP. One NSURLConnection per image. – kraftydevil Aug 29 '14 at 20:22
  • Okay, well that sounds simple enough. Just set the Content-Type and Content-Length headers appropriately, and put the data in the body... what's the problem? – Jon Skeet Aug 29 '14 at 20:25

1 Answers1

1

If you send something over the network, you are sending it as an actual byte array, so unless he means something else by byte array like base64 encoded in json, its that simple. In his controller on the server he will likely see or be able to retrieve the results of an HTTP POST or PUT in a stream or byte array. The link you posted is right, although now-a-days NSURLSession is probably the way to go:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlToPostTo];
request.HTTPMethod = @"POST";
request.HTTPBody = UIImagePNGRepresentation(imageToPost); //Or UIImageJPGRepresentation
[request setValue:@"image/png" forHTTPHeaderField:@"Content-Type"];
//Content-Length is usually not needed for servers, as there is no user interaction

NSURLSessionTask *dataTask = [self.session dataTaskWithRequest:request completionHandler:completionHandler];
[dataTask resume];
Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101