For full functionality of this site it is necessary to enable JavaScript.
Here are the instructions how to enable JavaScript in your web browser.

Knowledge base

Find the answer to your question

Advanced Search PView

Search terms
Search Type
Product
Category
Language
Format
SDK
Sort by
Direction

Upload pictures using eBay JAVA SDK

  • Answer ID 1452
  • Published 08/10/2009 01:48 AM
  • Updated 10/20/2013 06:41 AM
  • Permalink https://ebaydts.com/eBayKBDetails?KBid=1452
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_sdk595}/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="833";


  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

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter