rschluet9 avatar image
rschluet9 asked

Mac OS X error calling UploadSiteHostedPictures

I am creating a Mac OS X app for posting items to eBay. I have successfully added an item and the next step is to upload an image or images, which can then be referenced by that item. The API call is to the trading endpoint and is called UploadSiteHostedPictures I am using the NSURLSession and creating an NSURLSessionUploadTask. The error I get is: 5 1 SeriousError 0 0 RequestError XML Parse error. This is the first time I have attempted to use a multi-part post: Headers: { "Content-Type" = "multipart/form-data; boundary=0xKhTmLbOuNdArY"; "X-EBAY-API-APP-NAME" = "rSchluet-xxxx"; "X-EBAY-API-CALL-NAME" = UploadSiteHostedPictures; "X-EBAY-API-CERT-NAME" = "8b9c20xxxxx"; "X-EBAY-API-COMPATIBILITY-LEVEL" = 947; "X-EBAY-API-DETAIL-LEVEL" = 0; "X-EBAY-API-DEV-NAME" = "f439d8xxxxx"; "X-EBAY-API-SITEID" = 0; } The eBay API call instructions say: If you are using binary attachments (instead of external picture URLs), you must upload them using XML version 1.0. To include the picture as a binary MIME attachment, send it after the XML input in the same POST request. Here is the code creating the request: / NSXMLElement *rootElement = [[NSXMLElement alloc] initWithName:@"UploadSiteHostedPicturesRequest"]; [rootElement addAttribute:[NSXMLNode attributeWithName:@"xmlns" stringValue:@"urn:ebay:apis:eBLBaseComponents"]]; / NSXMLElement *requesterCredentialsElement = [[NSXMLElement alloc] initWithName:@"RequesterCredentials"]; NSXMLElement *authTokenElement = [[NSXMLElement alloc] initWithName:@"eBayAuthToken"]; authTokenElement.stringValue = sandboxUserToken; [requesterCredentialsElement addChild:authTokenElement]; [rootElement addChild:requesterCredentialsElement]; NSXMLElement *pictureNameElement = [[NSXMLElement alloc] initWithName:@"PictureName"]; pictureNameElement.stringValue = @"An Icon"; [rootElement addChild:pictureNameElement]; NSXMLDocument* xmlDocument = [NSXMLDocument documentWithRootElement:rootElement]; [xmlDocument setVersion:@"1.0"]; [xmlDocument setCharacterEncoding:@"utf-8"]; / NSMutableData* XMLStringAsData = [NSMutableData data]; [XMLStringAsData appendData:[[NSString stringWithFormat:@"--%@\r\n",multiPartBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [XMLStringAsData appendData:[xmlDocument.XMLString dataUsingEncoding:NSUTF8StringEncoding]]; / [XMLStringAsData appendData:[[NSString stringWithFormat:@"--%@\r\n",multiPartBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; NSString* filename = @"BestNegatives 20.jpg"; [XMLStringAsData appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\" filename=\"%@\"\r\n",filename]] dataUsingEncoding:NSUTF8StringEncoding]]; [XMLStringAsData appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [XMLStringAsData appendData:[NSData dataWithData: pictureData]]; [XMLStringAsData appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",multiPartBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:eBayUrl]; request.HTTPMethod = @"POST"; request.HTTPBody = XMLStringAsData; / NSURLSessionUploadTask* dataTask = [session uploadTaskWithRequest:request fromData:nil completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSLog(@"error: %@", error); NSLog(@"response: %@", response); NSString* dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"dataString: \n%@\n", dataString); } ]; [dataTask resume]; picureData is an NSData created with: NSData* picureData = [NSData dataWithContentsOfFile:imagePath]; and is a .jpg image. I am guessing that the server does not like the format of pictureData, but I don't know what to change. The error and response: 2016-01-05 13:19:27.156 eBayText[8839:3424158] error: (null) 2016-01-05 13:19:27.156 eBayText[8839:3424158] response: { URL: https:/ Connection = "keep-alive"; "Content-Length" = 339; "Content-Type" = "text/xml"; Date = "Tue, 05 Jan 2016 20:19:26 GMT"; Server = "Apache-Coyote/1.1"; "X-EBAY-API-POOL-NAME" = "___cDRudmd0YmtiZWx9ZWhxYA=="; "X-EBAY-API-SERVER-NAME" = "___dm8ucnA3MyhiZjZhZDM2Kjc3LTI3KTE8KD8zPz43OzU="; "X-EBAY-ESB-APP-NAME" = "rSchluet-xxx"; "X-EBAY-ESB-CALL-NAME" = UploadSiteHostedPictures; "X-EBAY-ESB-GUID" = "urn:uuid:23AE980B2xxxxxx"; "X-EBAY-ESB-SITEID" = 0; } } And the data returned: 2016-01-05 20:19:27 5 1 SeriousError 0 0 RequestError XML Parse error.
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.