Skip to main content
Published: August 10 2009, 1:48:00 AMUpdated: August 11 2022, 9:28:37 AM

Can I make UploadSiteHostedPictures API call directly via eBay Java SDK ?

Summary

   The sample java program below is written with eBay JAVA SDK framework. The code illustrates how to upload multiple images from a local file system to the eBay picture server.

  Java SDK uses UploadSiteHostedPictures, the only call in the Trading API that doesn't support SOAP, to upload image files in binary form.  The source code for using UploadSiteHostedPictures functionality can be found in the Java SDK com.ebay.sdk.pictureservice package : ${java_sdk}/source/core/src/com/ebay/sdk/pictureservice.


Detailed Description

/*
© 2009-2013 eBay Inc., All Rights Reserved
Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php
*/
import com.ebay.sdk.*;
import com.ebay.soap.eBLBaseComponents.*;
import com.ebay.sdk.pictureservice.*;
import com.ebay.sdk.pictureservice.eps.*;


public class AppUploadpicutre {

  private static String m_serverURL="https://api.ebay.com/ws/api.dll";
  private static String m_token="YOUR USER TOKEN";
  private static String m_outputFile;
  private static String imageFileName1="";
  private static String imageFileName2="";
  private static String[] pictureFiles = {imageFileName1,imageFileName2};
  private static String apiVersion="1235";


  public static void main(String[] args) { 

        try { 
              // apiContext object 
             ApiContext apiContext = new ApiContext(); 

             // Create credential object. 
             ApiCredential cred = apiContext.getApiCredential(); 
             cred.seteBayToken(m_token);

            //enable logging
            ApiLogging logging = new ApiLogging();
            apiContext.setApiLogging(logging);

            // set EpsServerUrl
           apiContext.setEpsServerUrl(m_serverURL);
           apiContext.setSite(SiteCodeType.US);
           apiContext.setWSDLVersion(apiVersion);

           //create PictureService object
           PictureService pictureService=eBayPictureServiceFactory.getPictureService(apiContext); 

          //build a PictureInfo array for holding multiple picture file names
           PictureInfo[] piList = new PictureInfo[pictureFiles.length];
           for(int i = 0; i < pictureFiles.length; i ++) {
                piList[i] = new PictureInfo();
                piList[i].setPictureFilePath(pictureFiles[i]);
          }

          int uploads = pictureService.uploadPictures (PhotoDisplayCodeType.NONE,piList);

          if (uploads !=0 ) {

              for(int i = 0; i < piList.length; i ++ ) { 

                      String errorMsg= piList[i].getErrorMessage() ;

                        if (piList[i].getReponse().getAck().compareTo(AckCodeType.FAILURE)==0){

                              System.out.print( piList[i].getErrorType() + " | " + errorMsg    ) ;

                        }else {

                               //http://developer.ebay.com/devzone/xml/docs/Reference/eBay/UploadSiteHostedPictures.html#Response.SiteHostedPictureDetails.FullURL 
                               // print out the generated image URL that can be used to associate with an item 

                              System.out.println (piList[i].getReponse().getSiteHostedPictureDetails().getFullURL());  

                              if (errorMsg !=null  && errorMsg.length() >0) {

                                  System.out.print( piList[i].getErrorType() + " | " + errorMsg    ) ;

                             };
                      }    

                 }                               

          }

    } catch(Exception e) { //handle exception here }
  }
}

 

Additional Resources

 

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