0

I want to implement a web service to recover an array of my entity PictureCaptures :

PictureCaptures
---------------
- description : string
- captureDate : DateTime
- photoBinary : byte[]

The web service will be mainly called by an iOS application.

What's the best way to implement it, because of the byte array attribute?

Am I suppose to return the byte array without any transformation, as a simple JSON attribute? If yes, how to interpet the JSON response ? -In this case JSONObjectWithData:options:error: doesn't work, too much data and memory issue)-

Thank you for your help.

βhargavḯ
  • 9,786
  • 1
  • 37
  • 59
ragu89
  • 335
  • 7
  • 22

2 Answers2

0

when you get JSON responce you shoud convert the btye array to NSData. first add Base64.h and m file to the project ( you can find it easily on internet)

then import Base64.h

from your JSON data

NSString *data= [yourJSONDict objectForKey:@"photoBinary"];
          NSData* imageData = [data base64DecodedData];

        UIImage *imag=[UIImage imageWithData:imageData];
        [yourImageView setImage:imag];

this might help you.

  • Yes but to recover a JSONDict I need to use the JSONObjectWithData:options:error method, and this make me a memory issue because I have a lot of picture in the data response. – ragu89 Dec 20 '13 at 09:51
  • if you post some code or what issue exaclty you get then someone can dafinately help you. –  Dec 20 '13 at 09:55
0

I would suggest you add two resources: one for the meta data (description, captureDate and so on) and one for the binary data. Let the meta data resource contain a link to the binary photo data.

Like this:

GET /images/1234

Response:

{
  description: "Nice photo",
  captureDate: "2012-04-23T18:25:43.511Z",
  photoData: "http://example.org/images/1234/photo"
}

and http://example.org/images/1234/photo returns the raw photo data

(see also See also The "right" JSON date format for a discussion on date formats).

Community
  • 1
  • 1
Jørn Wildt
  • 4,274
  • 1
  • 21
  • 31