Skip to main content
Published: June 22 2007, 4:42:00 PMUpdated: November 28 2020, 3:49:59 PM

.NET sample in C# for UploadSiteHostedPictures


Detailed Description

This C# example demonstrates how make a call to UploadSiteHostedPictures to upload a picture to eBay Picture Servers.
 

Note - This example is for sandbox, the use of a picutre URL, for Site 0 (US), using a button click for windows forms

/*
© 2007-2013 eBay Inc., All Rights Reserved
Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php
*/ 

string token = "your token here";

string SandboxURL = "https://api.sandbox.ebay.com/ws/api.dll";

string PictureURL = "your Picture URL here";

string DevID = "your DevID here";

string AppID = "your AppID here";

string CertID = "your CertID here";

string payload = "<?xml version=\"1.0\" encoding=\"utf-8\"?> " +

"<UploadSiteHostedPicturesRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">" +

"<ExternalPictureURL>" + PictureURL + "</ExternalPictureURL>" +

"<RequesterCredentials><eBayAuthToken>" + token + "</eBayAuthToken></RequesterCredentials>" +

"</UploadSiteHostedPicturesRequest>";

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(SandboxURL);

HttpWebResponse resp = null;

//Add the request headers

req.Headers.Add("X-EBAY-API-COMPATIBILITY-LEVEL", "803");

req.Headers.Add("X-EBAY-API-SITEID", "0");

req.Headers.Add("X-EBAY-API-CALL-NAME", "UploadSiteHostedPictures");

req.Headers.Add("X-EBAY-API-DEV-NAME", DevID);

req.Headers.Add("X-EBAY-API-APP-NAME", AppID);

req.Headers.Add("X-EBAY-API-CERT-NAME", CertID);

//set the method to POST

req.Method = "POST";

//Convert the string to a byte array

byte[] postDataBytes = System.Text.Encoding.ASCII.GetBytes(payload);

int len = postDataBytes.Length;

req.ContentLength = len;

//Post the request to eBay

System.IO.Stream requestStream = req.GetRequestStream();

requestStream.Write(postDataBytes, 0, len);

requestStream.Close();

try

{

// get response and write to console

resp = (HttpWebResponse)req.GetResponse();

StreamReader responseReader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);

string output = responseReader.ReadToEnd();

resp.Close();

XmlDocument xmlResponse = new XmlDocument();

xmlResponse.LoadXml(output);

//string response = xmlResponse.ToString();

//process response

//show them how to get the full url and specify that in the AddItem request

}

catch (Exception ex)

{

//handle exception

}


Here is a sample response that you will get:
 

 <?xml version="1.0" encoding="UTF-8"?>
<UploadSiteHostedPicturesResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2012-12-31T18:24:49.224Z</Timestamp
><Ack>Success</Ack>
<Version>803</Version>
<Build>E803_CORE_BUNDLED_15615944_R1</Build>
<PictureSystemVersion>2</PictureSystemVersion>
<SiteHostedPictureDetails>
<PictureSet>Standard</PictureSet>
<PictureFormat>JPG</PictureFormat>
<FullURL>http://i.ebayimg.sandbox.ebay.com/00/s/NzY4WDEwMjQ=/$(KGrHqFHJBMFBWFogSKOBQ4dh)!)tQ~~60_1.JPG?set_id=8800005007</FullURL>
<BaseURL>http://i.ebayimg.sandbox.ebay.com/00/s/NzY4WDEwMjQ=/$(KGrHqFHJBMFBWFogSKOBQ4dh)!)tQ~~60_</BaseURL>
<PictureSetMember>
<MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NzY4WDEwMjQ=/$(KGrHqFHJBMFBWFogSKOBQ4dh)!)tQ~~60_0.JPG</MemberURL>
<PictureHeight>72</PictureHeight>
<PictureWidth>96</PictureWidth>
</PictureSetMember>
<PictureSetMember>
<MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NzY4WDEwMjQ=/$(KGrHqFHJBMFBWFogSKOBQ4dh)!)tQ~~60_1.JPG</MemberURL>
<PictureHeight>300</PictureHeight>
<PictureWidth>400</PictureWidth>
</PictureSetMember>
<PictureSetMember>
<MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NzY4WDEwMjQ=/$(KGrHqFHJBMFBWFogSKOBQ4dh)!)tQ~~60_2.JPG</MemberURL>
<PictureHeight>150</PictureHeight>
<PictureWidth>200</PictureWidth>
</PictureSetMember>
<PictureSetMember>
<MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NzY4WDEwMjQ=/$(KGrHqFHJBMFBWFogSKOBQ4dh)!)tQ~~60_12.JPG</MemberURL>
<PictureHeight>375</PictureHeight>
<PictureWidth>500</PictureWidth>
</PictureSetMember>
<PictureSetMember>
<MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NzY4WDEwMjQ=/$(KGrHqFHJBMFBWFogSKOBQ4dh)!)tQ~~60_14.JPG</MemberURL>
<PictureHeight>48</PictureHeight>
<PictureWidth>64</PictureWidth>
</PictureSetMember>
<PictureSetMember>
<MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NzY4WDEwMjQ=/$(KGrHqFHJBMFBWFogSKOBQ4dh)!)tQ~~60_35.JPG</MemberURL>
<PictureHeight>225</PictureHeight>
<PictureWidth>300</PictureWidth>
</PictureSetMember>
<PictureSetMember>
<MemberURL>http://i.ebayimg.sandbox.ebay.com/00/s/NzY4WDEwMjQ=/$(KGrHqFHJBMFBWFogSKOBQ4dh)!)tQ~~60_39.JPG</MemberURL>
<PictureHeight>24</PictureHeight>
<PictureWidth>32</PictureWidth>
</PictureSetMember>
<ExternalPictureURL>http://www.personal.psu.edu/users/r/j/rjb333/PittsburghSteelers_Electric.jpg</ExternalPictureURL>
<UseByDate>2013-03-01T18:24:47.037Z</UseByDate>
</SiteHostedPictureDetails>
</UploadSiteHostedPicturesResponse>"

 

Version Info

The code example above was based on the versions specified below:

API Schema Version 803


Additional Resources

How well did this answer your question?
Answers others found helpful