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.

3
  • 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? Commented Aug 29, 2014 at 20:13
  • HTTP posts if we stick with what we've done before. Probably TCP/IP. One NSURLConnection per image. Commented Aug 29, 2014 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? Commented Aug 29, 2014 at 20:25

1 Answer 1

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];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.