cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Uploading Images in Binary format Using Ebay python SDK TRADING API UploadSiteHostedPictures call

I'm trying to figure out a way to upload images I have on my local computer using a file path and converting it to binary format so I don't have to host my images outside of ebay to get a url.  I know I could make my server public and grab the urls that way although if there's a way to take an image turn it into binary format and upload it to the ebay trading api using the UploadSiteHostedPictures call to get a url that way would be great.  Feel free to send a code sample thanks!

 

Message 1 of 7
latest reply
6 REPLIES 6

Re: Uploading Images in Binary format Using Ebay python SDK TRADING API UploadSiteHostedPictures cal

if you are using the sdk, you need to use "files", a dict for requests of {"name":photo} via the build_request function -> def build_request(self, verb, data, verb_attrs, files=None)

or, via requests alone below (I have not tried multiple photos yet, but testing 1 in sandbox works):

import requests

with open("YOUR_IMG.jpg", "rb") as f:
photo = f.read()

iaf = "YOUR_TOKEN"

headers = {
"X-EBAY-API-IAF-TOKEN": iaf,
"X-EBAY-API-COMPATIBILITY-LEVEL":"1295",
"X-EBAY-API-DEV-NAME":"YOUR_DEVID",
"X-EBAY-API-APP-NAME":"YOUR_CLIENTID",
"X-EBAY-API-CERT-NAME":"YOUR_CLIENTSECRET",
"X-EBAY-API-SITEID":"0",
"X-EBAY-API-CALL-NAME": "UploadSiteHostedPictures"
}

xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><UploadSiteHostedPicturesRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\"><PictureName>myphoto</PictureName><PictureSet>Supersize</PictureSet><ExtensionInDays>10</ExtensionInDays></UploadSiteHostedPicturesRequest>"


url = "https://api.sandbox.ebay.com/ws/api.dll"
data = { "XML Payload": xml.encode("UTF-8") }
files = { "myphoto": photo }
r = requests.Request(method="POST", url=url, data=data, headers=headers, files=files)
pr = r.prepare()
ses = requests.Session()
res = ses.send(pr)
print(res.content)

 

Message 2 of 7
latest reply

Re: Uploading Images in Binary format Using Ebay python SDK TRADING API UploadSiteHostedPictures cal

if you are using the sdk, you need to use the requests argument "files" via the build_request method -> def build_request(self, verb, data, verb_attrs, files=None)

(a dict in the format of {"name":photo}, photo being an open "rb" bytes file object of the photo)

or, via requests alone below (I have not tried multiple photos yet, but testing 1 in sandbox works):

 

import requests

with open("YOUR_IMG.jpg", "rb") as f:
photo = f.read()

iaf = "YOUR_TOKEN"

headers = {
"X-EBAY-API-IAF-TOKEN": iaf,
"X-EBAY-API-COMPATIBILITY-LEVEL":"1295",
"X-EBAY-API-DEV-NAME":"YOUR_DEVID",
"X-EBAY-API-APP-NAME":"YOUR_CLIENTID",
"X-EBAY-API-CERT-NAME":"YOUR_CLIENTSECRET",
"X-EBAY-API-SITEID":"0",
"X-EBAY-API-CALL-NAME": "UploadSiteHostedPictures"
}

xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><UploadSiteHostedPicturesRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\"><PictureName>myphoto</PictureName><PictureSet>Supersize</PictureSet><ExtensionInDays>10</ExtensionInDays></UploadSiteHostedPicturesRequest>"

url = "https://api.sandbox.ebay.com/ws/api.dll"
data = { "XML Payload": xml.encode("UTF-8") }
files = { "myphoto": photo }
r = requests.Request(method="POST", url=url, data=data, headers=headers, files=files)
pr = r.prepare()
ses = requests.Session()
res = ses.send(pr)
print(res.content)

 

Message 3 of 7
latest reply

Re: Uploading Images in Binary format Using Ebay python SDK TRADING API UploadSiteHostedPictures cal

This site filters responses with technical stuff in it.. attempt 3.. I will try splitting it up

 

if you are using the sdk, you need to use the requests argument "files" (a dict of {"name":photo}, photo being a open "rb" bytes object) via the method def build_request(self, verb, data, verb_attrs, files=None)

 

or, via requests alone below (I have not tried multiple photos yet, but testing 1 in sandbox works):

 

 

Message 4 of 7
latest reply

Re: Uploading Images in Binary format Using Ebay python SDK TRADING API UploadSiteHostedPictures cal

code part 1:

 


import requests

with open("YOUR_IMG.jpg", "rb") as f:
photo = f.read()

iaf = "YOUR_TOKEN"

headers = {
"X-EBAY-API-IAF-TOKEN": iaf,
"X-EBAY-API-COMPATIBILITY-LEVEL":"1295",
"X-EBAY-API-DEV-NAME":"YOUR_DEVID",
"X-EBAY-API-APP-NAME":"YOUR_CLIENTID",
"X-EBAY-API-CERT-NAME":"YOUR_CLIENTSECRET",
"X-EBAY-API-SITEID":"0",
"X-EBAY-API-CALL-NAME": "UploadSiteHostedPictures"
}
Message 5 of 7
latest reply

Re: Uploading Images in Binary format Using Ebay python SDK TRADING API UploadSiteHostedPictures cal

code part 2:



xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><UploadSiteHostedPicturesRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\"><PictureName>myphoto</PictureName><PictureSet>Supersize</PictureSet><ExtensionInDays>10</ExtensionInDays></UploadSiteHostedPicturesRequest>"

url = "THE_EBAY_TRADING_API_URL_ENDING_IN/ws/api.dll"
data = { "XML Payload": xml.encode("UTF-8") }
files = { "myphoto": photo }
r = requests.Request(method="POST", url=url, data=data, headers=headers, files=files)
pr = r.prepare()
ses = requests.Session()
res = ses.send(pr)
print(res.content)
Message 6 of 7
latest reply

Re: Uploading Images in Binary format Using Ebay python SDK TRADING API UploadSiteHostedPictures cal

Thanks I got the sdk working already.

Message 7 of 7
latest reply