How to post uiimage to soap Srevice in binary formate - iphone

I want to post uiimage into soap service and input image is into binary formate
"<ExpenseDetailReceipt>%#</ExpenseDetailReceipt>"
and send this appdelegate.imgBMeal data
appdelegate.imgBMeal=UIImagePNGRepresentation(appdelegate.imgMeal);
as image but there is some problem and I get please send data in correct formate
please help me how to do this

Soap is basically an xml which is a string. Hence, your UIImagePNGRepresentation(appdelegate.imgMeal) method which does not return a string fails. The output of the UIIagePNGRepresentation() is an NSData object which you can covert to a string by using Base64 encoding. (You may use any other encoding of your choice). For more about coverting NSData to NSString using Base64 encoding, there is an SO link with many answers.. here. You may also need to check with your service provider about the encoding decoding parts.

Related

Issue with decoding base64 encoded app engine data in swift

I am developing ios app which is getting data from Google endpoint ,the data is base 64 encoded on the server to a custom java object, which is then returned by the endpoint method.
On the iOS side I am able to receive the data and print the data using the generated client code.
I am facing a problem and I am unable to decode the data back in to the GTL**** endpoint auto generated class.
The decoded data shows up with some hex numbers:
My Code:
let respo2 = GTLDecodeBase64(responce) as? GTLEndpointStatusCollection
I also tried decoding using the swift classes:
let respo = NSData(base64EncodedString: responce, options: NSDataBase64DecodingOptions(rawValue: 0))
The input is base64 encoded : rO0ABXNyABNqYXZhLnV0aWwuQXJyYXlMaXN0eIHSHZnHYZ......
The desired output should have been readable data,
but instead im getting:
<aced0005 73720013 6a617661 2e757469 6c2e4172 7261794c.....
I even tried encoding, decoding the base64 decoded data with NSUTF8
but no use.
What am I doing wrong? Is it possible for data encoded on Server in Java (with custom Java objects) to be decoded back ? (I understand Google endpoint does the serialization/deserialization in between)
Thanks in advance.
You should use JSON for serialization rather than manually converting the object to a bytestring and base64 encoding it. If you are using the Endpoints libraries this is automatically done for you, simply by returning the object in your method. See the docs here for an example and the rest of the Endpoints docs for more details. To consume the API you can use the generated iOS libraries which also do this for you as per the examples here. You won't actually see any JSON unless you inspect the HTTP traffic or use the API Explorer.
It sounds like you might just be doing more work than is needed by pre-encoding the object, rather than just letting Endpoints do it for you. If you really need to manually serialize an object to some property you can use a library on the Endpoints side like Jackson to serialize the object to a string property and NSJSONSerialization on the client to convert it back to an object.

UIImage Base64 encoding fails

i'm trying to convert a UIImage which comes from the iPhones photo library to a base64 encoded string. My problem is that the output of the base64 encoded string does not match a base64 string which i've created on a online base64 encoder for jpegs.
Here is my code:
NSData *myAttachment = UIImageJPEGRepresentation(myImage, 1.0);
NSString *base64encodedAttachment = [attachment base64EncodingWithLineLenght:76];
While "attachment" is a string which will be part of an url request.
Why does the base64 code not match the "normal" from encoding websites encoding? Is there something special about UIImage oder NSData?
Cheers
It may happen that the UIImage is re-encoded when you call UIImageJPEGRepresentation and therefore it is not identical to the JPEG image you have uploaded to that online site. If you want to be 100% sure that the base64 encoder works as expected, save the JPEG representation that comes out of UIImageJPEGRepresentation to a JPEG file and upload that file to the online tool to obtain the base64 representation to compare your output with.
If you are trying to use this jpeg file in the messageBody of the mailComposer.. then i must clear you buddy...
You cannot use the local images inside the mailbody of mailComposer, the image shud be available on the server and used in the mailbody by passing url of the same..
If you're trying something else...i would say follow "Tamas" :)

XML data text + binary

I built an iPhone app that is getting information from a server (this is also a server that I built).
The data from the server is XML and I use the XML parser to parse the message.
What I want is to add an image to be sent from the server, and I am asking if I can add binary data of such an image to the XML message. For example 10 tags will be text and 1 tag will be binary (the image). So when the XML parser gets to the binary tag, it inserts the data to NSDATA object and the rest of the tags will be inserted to NSString.
Does the XML parser of Cocoa can handle this situation?
If not, what do you think will be the easiest way to do this with one connection to the server so that the data from the server is sent once.
To transfer binary data wrapped in XML, encode it using e.g. Base64, which turns your binary data into characters that won't mess up your XML.
You can transfer the image data, encoded using Base64. There is this NSData category by Matt Gallagher that adds Base64 decoding support to NSData (dateFromBase64String). You can find it on his Cocoa with love website.
Mind you that encoding images in Base64 adds about 33% in file size.

Get NSString/NSData object from hardcoded bytes saved as NSString object in webservice response

I am working with the iPhone SDK and I have to process a webservice response I receive from an external service.
The response data consists of an XML string that was UTF8-encoded to a byte array.
This byte array is converted to string
This string is put into a XML wrapper element
The wrapper is returned via an HTTP response
Therefore I need to know how to convert the response data back to the XML string it used to be. Unfortunately, I cannot change the way my response is created, so I have to deal with it somehow.
Example of the raw data I get from the webservice:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body><ExportBytesResponse xmlns="http://knowledgepark-ag.com/webservices/">
<ExportBytesResult>PERhdGE+PFJlY29yZCBEQj0iOTk5OTQiIEtleT0iMjA1Mjc0Ij48U2luZ2xlIEl0ZW1JZD0iQVJCUEFLRVQiIFZhbHVlPSIyOTAiIC8+PFNpbmdsZSBJdGVtSWQ9IkhET0tOUiIgVmFsdWU9IjIwNTI3NCIgLz48U2luZ2xlIEl0ZW1JZD0iVkVSQSIgVmFsdWU9IjEuNzEuMzIxMy4xNzU3NyIgLz48U2luZ2xlIEl0ZW1JZD0iRElTIiBWYWx1ZT0iR2VNLCBNw6RyIDEwIDIwMDggIDU6NDFQTTomI3hEO1ouenQuIGV4aXNpdGVydCBrZWluZSBNw7ZnbGljaGtlaXQgZGFzIEJlZW5kZW4gZWluZXMgTW9kdWxzIGR1cmNoIEFiYnJlY2hlbiBvZGVyIEhhcmQtQ2xvc2UtWCB6dSBlcmZhaHJlbi4gQW4gZGllc2VyIFN0ZWxsZSBtw7xzc3RlbiBtZWlzdCBVc2VydmFycyBkZXMgTW9kdWxzIGdlbMO2c2NodCB3ZXJkZW4uIE9kZXIgYW5kZXJlIEF1ZnLDpHVtYWt0aW9uIGR1cmNoZ2Vmw7xocnQgd2VyZGVuLiYjeEE7RUxLRUcgMDYuMDguMjAwOCAwOToyMToxNyYjeEE7JiN4QTsgQmVpc3BpZWxhdWZiYXUgOiYjeEQ7JiN4QTsmbHQ7Q2xv</ExportBytesResult>
</ExportBytesResponse></s:Body>
How do I get back my old xml string representation hidden inside these raw bytes?
Any help is highly appreciated, I feel just stupid right now for not being able to come up with a solution.
Best Regards,
David
ExportBytesResponse is Base64 encoded, so you must first decode that node using something like this.
That will give you an NSString containing the XML. Then you can use NSXMLParser to parse your data.

Retrieving images to iphone app through XML

I have made an iphone application in which data is retrieved from remote server through xml saved. I want to retrieve images also with in the XMl and have to show them in my iphone application stored on server. Please help how this can be achieved.
In my application I am both sending and receiving images through Xml. In order to facilitate this, I encode/decode the images using base64 encoding. MY encode/decode methods live in 2 objective-c categories, 1 for NSData and 1 for NSString. You call these methods on the respective data types, I have listed examples below. The methods are [NSData base64Encoding] and [NSString base64Decoding].
When sending to the server...
NSLog(#"Compressing Image: JPEG 80%");
NSData *imgData = UIImageJPEGRepresentation(scaledImage, 0.8f);
NSString *b64String = [imgData base64Encoding];
My "b64String" variable now has a base64 encoded string representation of my image. You can now wrap this in Xml and use your normal NSURLConnection to send it to the server.
When receiving from the sever... (Make sure you are sending base64 encoded text from the server)
You will do your normal Xml parsing, here my "value" variable holds the base64 string from the server.
NSData *imgData = [value base64Decoding];
UIImage *image = [[UIImage alloc] initWithData:imgData];
You should be able to look up some common base64 encoding/decoding algorithms in Objective-C, let me know if you would like me to post my methods (they are kinda long so I obmitted them here).
I'm writing an app at the moment that has this problem - I've solved it by putting a url to the image in the xml instead of embedding the image data itself. For example my xml looks something like this :
<images>
<image url="http://www.example.com/images/12345.jpg" />
<image url="http://www.example.com/images/67890.jpg" />
</images>
As I'm parsing the xml, when I hit an < image > tag I store the url in an NSMutalbeArray. When the xml is parsed I loop through the array and get each image using NSURLConnection.
Sam
PS I worked out how to use NSURLConnection from this page : https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html