0

How do I attach an image to an XML file in Objective-C to POST to a WebService?

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<SaveRequest>
    <PictureDataFile></PictureDataFile>
    <PictureDataName>sample</PictureDataName>
</SaveRequest>

How do I append the image data into 'PictureDataFile'?

And in my objective-C I have,

NSString *post = [self loadFileName:@"SaveRequest" ofType:@"xml"];
//loads the xml into a string
NSMutableData *postData = [[post dataUsingEncoding:NSUTF8StringEncoding    allowLossyConversion:YES] mutableCopy];
[postData appendData:paramBuilder.imageData];
//paraBuilder.imageData contains a UIImage in NSData

I can see the server receive the request, but no image data is received. Thanks for any help in advance.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
ginoOwnits
  • 29
  • 5

1 Answers1

1

I figured it out, in case anyone runs into the same issue: convert the nsdata to base64 by using

[NSData base64EncodedDataWithOptions:]

therefore attach the base64 data to the node like this :

[postData appendData:[imageData base64EncodedDataWithOptions:NSDataBase64Encoding64CharacterLineLength]];
ginoOwnits
  • 29
  • 5