question

astudentofthegame avatar image
0 Likes"
astudentofthegame asked

Why is the UploadSiteHostedPictures service saying my image is corrupt?

I am following this article: https://developer.ebay.com/devzone/xml/docs/reference/ebay/UploadSiteHostedPictures.html#UploadingBinaryImages

MIME Boundary:

mimeBoundary = '--MIME_boundary'

Headers:

requestHeaders = {
    'X-EBAY-API-CALL-NAME': 'UploadSiteHostedPictures',
    'X-EBAY-API-SITEID': '0',
    'X-EBAY-API-RESPONSE-ENCODING': 'XML',
    'X-EBAY-API-COMPATIBILITY-LEVEL': '1113',
    'X-EBAY-API-DETAIL-LEVEL': '0',
    'Cache-Control': 'no-cache',
    'X-EBAY-API-DEV-NAME': devid,
    'X-EBAY-API-APP-NAME': appid,
    'X-EBAY-API-CERT-NAME': certid,
    'MIME-Version': '1.0',
    'Content-Type': 'multipart/form-data; boundary=' + mimeBoundary
}

Request payload:

--MIME_boundary
Content-Disposition: form-data; name="XML Payload"
Content-Type: text/xml;charset=utf-8

<?xml version="1.0" encoding="utf-8"?>
<UploadSiteHostedPicturesRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<ebl:eBayAuthToken xmlns:ebl="urn:ebay:apis:eBLBaseComponents">TOKEN</ebl:eBayAuthToken>
</RequesterCredentials>
<PictureName>Scarlett</PictureName>
<PictureSet>Standard</PictureSet>
<ExtensionInDays>20</ExtensionInDays>
</UploadSiteHostedPicturesRequest>


--MIME_boundary
Content-Disposition: form-data; name="Scarlett"; filename="Scarlett.jpeg"
Content-Type: image/jpeg
/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gODAK/9sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBgXFBYWGh0lHxobIxwWFiAsICMm
<truncated for posting>
JykqKRkfLTAtKDAlKCko/9sAQwEHBwcKCAoTCgoTKBoWGigoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo/8AAEQgHCwSwAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAA==
--MIME_boundary--

Response:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<UploadSiteHostedPicturesResponse
  xmlns="urn:ebay:apis:eBLBaseComponents">    
  <Timestamp>2022-11-20T08:59:18.207Z</Timestamp>    
  <Ack>Failure</Ack>    
  <Errors>        
    <ShortMessage>File has corrupt image data</ShortMessage>        
    <LongMessage>Picture Services found a data corruption problem when processing retrieved picture file</LongMessage>        
    <ErrorCode>21916550</ErrorCode>        
    <SeverityCode>Error</SeverityCode>        
    <ErrorParameters ParamID="0"/>        
    <ErrorClassification>RequestError</ErrorClassification>    
  </Errors>    
  <Version>0</Version>    
  <Build>mediasvcs-5.0.26_20221111221002304</Build>    
  <PictureSystemVersion>2</PictureSystemVersion>
</UploadSiteHostedPicturesResponse>


I am posting this to

https://api.sandbox.ebay.com/ws/api.dll


Can you share a working example in python for uploading a jpg file from local disk to the EPS?

pythoneps upload problems
· 2
10 |600

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

michab2003 avatar image michab2003 commented ·
python: no, maybe you can find here something that helps:


https://github.com/michabbb/php-ebay-upload-images/blob/master/upload_images.php#L73

0 Likes 0 ·
astudentofthegame avatar image astudentofthegame michab2003 commented ·
Thanks for the reply. I just got it working from python using one of the code samples in ebaysdk-python that I missed initially.
0 Likes 0 ·

1 Answer

·
astudentofthegame avatar image
0 Likes"
astudentofthegame answered

I just spent a ton of time trying to get image uploads working by directly posting MIME-formatted messages to the API, come to find out the ebaysdk-python sample code has a great example that kindly hides all the gory MIME and XML details:

filename = r"C:\Users\name\Downloads\scarlett.jpeg"
 
api = Trading(debug=True, config_file="ebay.yaml", domain="api.sandbox.ebay.com", warnings=True)
 
# pass in an open file
# the Requests module will close the file
files = {'file': ('EbayImage', open(filename, 'rb'))}
 
pictureData = {
    "WarningLevel": "High",
    "PictureName": "Scarlett"
}
 
api.execute('UploadSiteHostedPictures', pictureData, files=files)
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.