question

huwktw avatar image
0 Likes"
huwktw asked

[delphi][C#] UploadSiteHostedPictures Return "20170 Bad character or insufficient number of characters in hex string"

Hi when I call "UploadSiteHostedPictures" get "ERemotableException:java.lang.IllegalArgumentException: Bad character or insufficient number of characters in hex string" error exception~ Code like this addpictureRequest := UploadSiteHostedPicturesRequest.Create; addpictureRequest.Version := '869'; addpictureRequest.PictureName :='MyTEST1234'; addpictureRequest.PictureData := Base64BinaryType.Create; addpictureRequest.PictureData.contentType :='image/jpeg'; addpictureRequest.PictureData.Text := mybytearray; try addpictureResponse := Ebay_Int.UploadSiteHostedPictures(addpictureRequest); Memo2.Lines.Add(addpictureResponse.SiteHostedPictureDetails.FullURL) except on e:Exception do begin Memo2.Lines.Add('ERROR:'+e.ClassName+':'+e.Message); end; end; then I try use "API Test Tool Website" to test it xml Request: [link text][1] it Return [link text][2] My upload picture Like this http://goo.gl/XpcwMv Am I missing something? Thanks! [1]: /storage/temp/262-xml+ request.txt [2]: /storage/temp/263-call+ response.txt I try C# .get same error Message string signinURL = " https://api.sandbox.ebay.com/wsapi"; string callname = "UploadSiteHostedPictures"; string siteID = "0"; string appID = "IDID"; string version = "768"; string eBayToken = "TOKEN"; string endpointURL = signinURL + "?callname=" + callname + "&siteid=" + siteID + "&appid=" + appID + "&version=" + version + "&routing=default"; //eBayAPIInterfaceClient service = new eBayAPIInterfaceClient("eBayAPI", endpointURL); eBayAPIInterfaceClient service = new eBayAPIInterfaceClient("eBayAPI", signinURL); EndpointAddress address = new EndpointAddress(endpointURL); service.Endpoint.Address = address; CustomSecurityHeaderType cred = new CustomSecurityHeaderType(); cred.eBayAuthToken = eBayToken; UploadSiteHostedPicturesRequestType request = new UploadSiteHostedPicturesRequestType(); request.Version = version; request.WarningLevelSpecified = true; request.WarningLevel = WarningLevelCodeType.High; System.IO.FileStream inFile; byte[] binaryData; inFile = new System.IO.FileStream(@"d:\11.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read); binaryData = new Byte[inFile.Length]; long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length); inFile.Close(); request.PictureName = "HELLABC"; request.PictureData = new Base64BinaryType(); request.PictureData.contentType = "image/jpeg"; request.PictureData.Value = binaryData; UploadSiteHostedPicturesResponseType res = service.UploadSiteHostedPictures(ref cred, request); textBox1.Text = res.Ack.ToString() + ":" + res.SiteHostedPictureDetails.FullURL;
uploadsitehostedpicturesdelphi
xml request.txt (6.0 KiB)
call response.txt (1.5 KiB)
10 |600

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

1 Answer

·
devanathan.developersupport@ebay.com avatar image
0 Likes"
devanathan.developersupport@ebay.com answered
Hello huwktw, I can re-produce the same error in .NET environment when using a service reference to the Trading WSDL. Whereas, I can run the UploadSiteHostedPictures call using a request stream and getting a response stream. Try the following code; public static void Main(string[] args) { //read the image file as a byte array string imagefile = @"C:\Test-Image.jpg"; System.IO.FileStream fs = new System.IO.FileStream(imagefile, FileMode.Open, FileAccess.Read); fs.Seek(0, SeekOrigin.Begin); System.IO.BinaryReader br = new System.IO.BinaryReader(fs); byte[] image = br.ReadBytes((int)fs.Length); br.Close(); fs.Close(); // Sandbox //HttpWebRequest req = (HttpWebRequest)WebRequest.Create(" https://api.sandbox.ebay.com/ws/api.dll"); // Production HttpWebRequest req = (HttpWebRequest)WebRequest.Create(" https://api.ebay.com/ws/api.dll"); HttpWebResponse resp = null; string boundary = "MIME_boundary"; string CRLF = "\r\n"; //Add the request headers req.Headers.Add("X-EBAY-API-COMPATIBILITY-LEVEL", "859"); req.Headers.Add("X-EBAY-API-SITEID", "0"); req.Headers.Add("X-EBAY-API-DETAIL-LEVEL", "0"); req.Headers.Add("X-EBAY-API-CALL-NAME", "UploadSiteHostedPictures"); req.ContentType = "multipart/form-data; boundary=" + boundary; //set the method to POST req.Method = "POST"; //replace token with your own token // sandbox //string token = "Your_Sandbox_Token_Here"; // production string token = "Your_Production_Token_Here"; //Construct the request string strReq1 = "--" + boundary + CRLF + "Content-Disposition: form-data; name=document" + CRLF + "Content-Type: text/xml; charset=\"UTF-8\"" + CRLF + CRLF + " " + " " + " " + " " + token + " " + " " + " Supersize " + " " + CRLF + "--" + boundary + CRLF + "Content-Disposition: form-data; name=image; filename=image" + CRLF + "Content-Type: application/octet-stream" + CRLF + "Content-Transfer-Encoding: binary" + CRLF + CRLF; string strReq2 = CRLF + "--" + boundary + "--" + CRLF; //Converting string to a byte array byte[] postDataBytes1 = System.Text.Encoding.ASCII.GetBytes(strReq1); byte[] postDataBytes2 = System.Text.Encoding.ASCII.GetBytes(strReq2); int len = postDataBytes1.Length + postDataBytes2.Length + image.Length; req.ContentLength = len; //Post the request to eBay System.IO.Stream requestStream = req.GetRequestStream(); requestStream.Write(postDataBytes1, 0, postDataBytes1.Length); requestStream.Write(image, 0, image.Length); requestStream.Write(postDataBytes2, 0, postDataBytes2.Length); requestStream.Close(); string response; try { // get response and write to console resp = (HttpWebResponse)req.GetResponse(); StreamReader responseReader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8); response = responseReader.ReadToEnd(); resp.Close(); //response contains our pictures url System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.LoadXml(response); //Extract the FullURL from the response XmlNode root = xml["UploadSiteHostedPicturesResponse"]; //There have been Errors if (root["Errors"] != null) { string errorCode = root["Errors"]["ErrorCode"].InnerText; string errorShort = root["Errors"]["ShortMessage"].InnerText; string errorLong = root["Errors"]["LongMessage"].InnerText; //Output the error message Console.WriteLine(errorCode + " ERROR: " + errorShort); Console.WriteLine(errorLong + "\n"); } else { //Display the result Console.WriteLine(""); Console.WriteLine("FullURL : " + root["SiteHostedPictureDetails"]["FullURL"].InnerText); Console.WriteLine("MemberURL : " + root["SiteHostedPictureDetails"]["PictureSetMember"]["MemberURL"].InnerText); Console.WriteLine("Uploaded Time: " + DateTime.Parse(root["Timestamp"].InnerText).ToString("dd-MMM-yyyy HH:mm:ss") + " GMT"); Console.WriteLine("--------------------------------------------------------------------"); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } Console.WriteLine("Press enter key exit..."); Console.ReadLine(); } Best Regards, Devanathan Sampath, eBay Developer Support
10 |600

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

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.