question

sales69-llc avatar image
0 Likes"
sales69-llc asked

UploadSiteHostedPictures Include a binary attachment Question

Hi all,

 

We are unable to get the binary attachment feature to work of the UploadSiteHostedPictures API. 

 

Using c# we are able to upload pictures to the eBay picture service if our pictures are hosted on an external website.

 

After searching these forums and google we can't find a single working example of this feature. Lots of people asking how to make it work, not a single working example posted.

 

So, our question is: Has anyone here successfully upload a picture using the binary attachment feature of the UploadSiteHostedPictures API. And if yes, can you please post an example.

 

Thank you,

Stan

 

 

uploadsitehostedpicturesmimebinary
10 |600 characters needed characters left characters exceeded

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

shulmani_developer.support avatar image
0 Likes"
shulmani_developer.support answered

Hi,

 

We have a Knowledge Base article for this : https://ebaydts.com/eBayKBDetails?KBid=1561

Can you check if this works fro you?

 

 

Cheers!!!

10 |600 characters needed characters left characters exceeded

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

sales69-llc avatar image
0 Likes"
sales69-llc answered

Hi, thank you for the response, however it is written in PHP. We need an example written in C# or VBA.

 

Thanks,

David

10 |600 characters needed characters left characters exceeded

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

claudiasallerlei avatar image
1 Like"
claudiasallerlei answered
'Here is the VBA Code Public Function Uploadpicture() As String On Error Resume Next Dim dlg As FileDialog Dim strFileName As String Dim strXMLRequest As String Dim errMessage As String Dim errMessage 2 As String Dim strCallname As String Dim objXMLResponse As MSXML2.DOMDocument Dim objXMLItems As MSXML2.IXMLDOMElement Dim Url As String Dim PictureHeight As String Dim PictureWidth As String Dim i As Long Dim strAck As String Dim boundary As String Dim db As DAO.Database Dim FirstPart As String Dim secondPart As String Dim sPostData As String Dim nFile As Integer Dim baBuffer() As Byte boundary = "MIME_boundary" Set dlg = FileDialog(msoFileDialogFilePicker) 'open Dialog If dlg.Show = -1 Then 'on select strFileName = dlg.SelectedItems(1) GoTo weiter End If MsgBox "No File" Uploadpicture= "" Exit Function weiter: DoCmd.Hourglass True Set dlg = Nothing Set db = CurrentDb ' Picture import and convert nFile = FreeFile Open strFileName For Binary Access Read As nFile If LOF(nFile) > 0 Then ReDim baBuffer(0 To LOF(nFile) - 1) As Byte Get nFile, , baBuffer sPostData = StrConv(baBuffer, vbUnicode) End If Close nFile 'create the XML strCallname = "UploadSiteHostedPictures" strXMLRequest = " " & vbCrLf strXMLRequest = strXMLRequest & " " & vbCrLf strXMLRequest = strXMLRequest & " " & vbCrLf strXMLRequest = strXMLRequest & " " & "yourtokenhere" & " " & vbCrLf strXMLRequest = strXMLRequest & " " & vbCrLf strXMLRequest = strXMLRequest & " " & "945" & " " & vbCrLf strXMLRequest = strXMLRequest & " " FirstPart = "''" FirstPart = FirstPart & "--" & boundary & vbCrLf FirstPart = FirstPart & "Content-Disposition: form-data; name=""XML Payload"" & vbCrLf" FirstPart = FirstPart & "Content-Type: text/xml;charset=utf-8" & vbCrLf & vbCrLf FirstPart = FirstPart & strXMLRequest 'add the FirstPart = FirstPart & vbCrLf secondPart = "--" & boundary & vbCrLf secondPart = secondPart & "Content-Disposition: form-data; name=""dummy""; filename=""dummy"" & vbCrLf" secondPart = secondPart & "Content-Transfer-Encoding: binary" & vbCrLf secondPart = secondPart & "Content-Type: application/octet-stream" & vbCrLf & vbCrLf secondPart = secondPart & sPostData 'add the Picture secondPart = secondPart & vbCrLf secondPart = secondPart & "--" & boundary & "--" & vbCrLf strXMLRequest = FirstPart & secondPart With CreateObject("Microsoft.XMLHTTP") .Open "POST", " https://api.sandbox.ebay.com/ws/api.dll", False .setRequestHeader "X-EBAY-API-CALL-NAME", strCallname .setRequestHeader "X-EBAY-API-REQUEST-ENCODING", "XML" .setRequestHeader "X-EBAY-API-RESPONSE-ENCODING", "XML" .setRequestHeader "X-EBAY-API-SITEID", "0" .setRequestHeader "X-EBAY-API-APP-NAME", "yourAppID" 'AppID .setRequestHeader "X-EBAY-API-DEV-NAME", "yourDevID" 'DevID .setRequestHeader "X-EBAY-API-Cert-NAME", "YourCertID" 'CertID .setRequestHeader "X-EBAY-API-VERSION", "945" 'APi Version .setRequestHeader "X-EBAY-API-COMPATIBILITY-LEVEL", "945" .setRequestHeader "Content-Type", "multipart/form-data; boundary=" & boundary .send pvToByteArray(strXMLRequest) If .Status = 200 Then errMessage = "" errMessage2 = "" Set objXMLResponse = .responseXML 'Response einlesen Debug.Print Replace(.responseText, "><", ">" & vbCrLf & "<") 'display the full Responsetext strAck = objXMLResponse.selectSingleNode("UploadSiteHostedPicturesResponse/Ack").nodeTypedValue Debug.Print strAck If strAck = "Success" Or strAck = "warning" Then 'Debug.Print Replace(objXMLResponse.XML, "><", ">" & vbCrLf & "<") Set objXMLItems = objXMLResponse.selectSingleNode("UploadSiteHostedPicturesResponse/SiteHostedPictureDetails") errMessage = "Warning: " & objXMLResponse.selectSingleNode("UploadSiteHostedPicturesResponse/Errors/LongMessage").nodeTypedValue uploadpicture = objXMLResponse.selectSingleNode("UploadSiteHostedPicturesResponse/SiteHostedPictureDetails/FullURL").nodeTypedValue For i = 0 To objXMLItems.childNodes.length - 1 Url = objXMLItems.childNodes(i).selectSingleNode("MemberURL").nodeTypedValue PictureWidth = objXMLItems.childNodes(i).selectSingleNode("PictureWidth").nodeTypedValue PictureHeight = objXMLItems.childNodes(i).selectSingleNode("PictureHeight").nodeTypedValue If objXMLItems.childNodes(i).baseName = "PictureSetMember" Then Debug.Print "URL= " & Url Debug.Print "Width = " & PictureWidth Debug.Print "Height = " & PictureHeight End If Next i ElseIf strAck = "Failure" Then Debug.Print "Errors/ShortMessage: " & objXMLResponse.selectSingleNode("UploadSiteHostedPicturesResponse/Errors/ShortMessage").nodeTypedValue Debug.Print "Errors/LongMessage: " & objXMLResponse.selectSingleNode("UploadSiteHostedPicturesResponse/Errors/LongMessage").nodeTypedValue errMessage = "Error: " & objXMLResponse.selectSingleNode("UploadSiteHostedPicturesResponse/Errors/LongMessage").nodeTypedValue uploadpicture = "" End If errMessage2 = objXMLResponse.selectSingleNode("UploadSiteHostedPicturesResponse/Errors/LongMessage").nodeTypedValue If errMessage2 <> "" Then MsgBox errMessage End If End With DoCmd.Hourglass False End Function Private Function pvToByteArray(sText As String) As Byte() pvToByteArray = StrConv(sText, vbFromUnicode) End Function
· 1
10 |600 characters needed characters left characters exceeded

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

I know this post is ancient, but this helped a ton. @claudiasallerlei - thanks a million for this post, got me through a bunch of blockades I was having.
0 Likes 0 ·
coconutsmo avatar image
0 Likes"
coconutsmo answered
If youre testing this in the sandbox you need to loop the code in a retry block, because sometimes the request returns Failure but it may work on the next try.
10 |600 characters needed characters left characters exceeded

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.