Skip to main content
Published: October 16 2008, 5:43:00 PMUpdated: September 07 2022, 7:22:12 AM

VB.NET sample for UploadSiteHostedPictures

Detailed Description

This VB.NET 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 windows forms button click

 

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

Imports System

Imports System.IO

Imports System.Text

Imports System.Xml

Imports System.Net

 

 

Public Class Form1

Dim fullURL, ImageFile As String

Dim token As String = "your token here"

Dim SandboxURL As String = "https://api.sandbox.ebay.com/ws/api.dll"

Dim PictureURL As String = "your Picture URL here"

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

 

Dim payload As String = "<?xml version=""1.0"" encoding=""utf-8""?> " +

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

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

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

"</UploadSiteHostedPicturesRequest>"

 

Dim req As HttpWebRequest = WebRequest.Create(SandboxURL)

Dim resp As HttpWebResponse = Nothing

 

'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")

'set the method to POST

req.Method = "POST"

 

'Convert the string to a byte array

Dim postDataBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(payload)

Dim len As Integer = postDataBytes.Length

req.ContentLength = len

 

'Post the request to eBay

Dim requestStream As Stream = req.GetRequestStream()

requestStream.Write(postDataBytes, 0, Len)

requestStream.Close()

 

Try

 

'get response and write to console

resp = req.GetResponse()

Dim responseReader As StreamReader = New StreamReader(resp.GetResponseStream(), Encoding.UTF8)

Dim output As String = responseReader.ReadToEnd()

resp.Close()

 

Dim xmlResponse As New XmlDocument()

xmlResponse.LoadXml(output)

 

'process response

 

Catch ex As Exception

 

'handle exception

End Try

End Sub

End Class

 

 

 

Here is a sample response that you would get:

 

<?xml version="1.0" encoding="UTF-8"?>
<UploadSiteHostedPicturesResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2022-06-30T18:24:49.224Z</Timestamp
><Ack>Success</Ack>
<Version>1235</Version>

<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>"

 

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