02-16-2023 08:24 AM
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!
02-20-2023 11:11 PM
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)
02-20-2023 11:19 PM
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)
02-20-2023 11:30 PM
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):
02-20-2023 11:32 PM
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"
}
02-20-2023 11:34 PM
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)
02-21-2023 05:33 AM
Thanks I got the sdk working already.