kraftydevil
kraftydevil

Reputation: 5246

Sending an image via byte array from iOS to a .net server

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.

Upvotes: 1

Views: 850

Answers (1)

Peter DeWeese
Peter DeWeese

Reputation: 18333

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];

Upvotes: 1

Related Questions