上传多张图片至ebay的总结

最近需要帮助ebay sales部门实现能够针对一种产品上传多张图片,在查看Ebay Call Reference,原以为找一个ebay Call 就能够搞定,这次算了思路有问题。还好jack的代码给很大的帮助。下面看看Call Reference中关于UploadSiteHostedPictures。这个就是用于将图片上传到ebay的关键。
[quote]
UploadSiteHostedPictures
Use this call to upload a picture to eBay Picture Services (EPS). Include a binary attachment or supply a URL in the ExternalPictureURL field to the location of the picture on an external web server.

Unlike what the call name implies, you can only upload one picture per call. To upload multiple pictures, call UploadSiteHostedPictures once for each item image you want to upload. Uploading many picture images at once allows the images to be available in the EPS before you upload the data for the corresponding item listing (for example, by calling AddFixedPriceItem).

UploadSiteHostedPictures supports only the XML Trading API (the SOAP Trading API is not supported). If you are using binary attachments (instead of external picture URLs), you must upload them using XML version 1.0. Include the picture as a binary MIME attachment, sent after the XML input in the same POST request.

If you set PictureSet to Supersize, and the response confirms that a Supersize or Large image set was created, then calls to create a listing (for example, with AddItem or ReviseItem) must specify Supersize or PicturePack in the PhotoDisplayType field. If there are existing pictures for a listing when you call ReviseItem, you can not change the PhotoDisplayType property from Normal to Supersize or PicturePack.

If the call is successful, UploadSiteHostedPictures returns a URL value for the picture in SiteHostedPictureDetails.FullURL. Store the URL for use in an Item.PictureDetails.PictureURL field when you list your item (for example, with a call to AddItem, ReviseItem, or RelistItem). Note that there is no API call for finding the URL of an uploaded, unassociated picture, so be sure to save the returned URL value. Be aware that you must add an item that uses the uploaded images within five days for Trading API calls and within ten days for Large Merchant Services calls; unassociated pictures are automatically deleted after that period.

If you are using eBay Large Merchant Services (LMS), you can include multiple calls to UploadSiteHostedPictures, with different picture URLs in each call, within an LMS data file. See The eBay Large Merchant Services User Guide for more information about eBay Large Merchant Services. Note that uploading attachments is not supported for eBay Large Merchant Services; you must upload the images using an ExternalPictureURL field.
[/quote]
这段描述主要理解了,这个不支持SOAP传输,jack的代码中直接发送xml到ebay 是EPS服务器,来获取url。

主要原理:将sales自己的picture URL上传到ebay 的EPS服务器得到ebay存放sales picture的URL。得到这些URL后,就能够在ebay上显示。
下面看看代码:

// 获取从ebay返回的pictureURL
private static String[] getEbayPictureURL(String serverURL, String token,String[] PictureURLs) throws IOException{

List<String> temp = new ArrayList<String>();
for(int i=0; i<PictureURLs.length;i++){
String format_PictureURLs=PictureURLs[i];
String requestStr =SendXmlRequest(token,format_PictureURLs.trim());
HttpClient client = new HttpClient();
PostMethod filePost = new PostMethod(serverURL);
filePost.addRequestHeader("X-EBAY-API-CALL-NAME","UploadSiteHostedPictures");
StringRequestEntity req = new StringRequestEntity(requestStr,"text/plain","UTF-8");
filePost.setRequestEntity(req);
filePost.addRequestHeader("SOAPAction","");
filePost.addRequestHeader("X-EBAY-API-COMPATIBILITY-LEVEL","685");
filePost.addRequestHeader("X-EBAY-API-SITEID","0");
filePost.addRequestHeader("X-EBAY-API-DETAIL-LEVEL","0");


client.executeMethod(filePost);

String result = filePost.getResponseBodyAsString();

int head = result.indexOf("<FullURL>");
int tail = result.indexOf("</FullURL>");
if(head >0){
String ebayURL = result.substring(head+9, tail);
temp.add(ebayURL);
}
}

String pictureURL[] = new String[temp.size()];
for( int i = 0;i<temp.size();i++ )
{
pictureURL[i] = temp.get( i );
}
if(pictureURL.length >0){
return pictureURL;
}
return null;
}


/**
* 将自己的URL发送给ebay
* @param token
* @param imageURL
* @return
*/
private static String SendXmlRequest(String token, String imageURL){

if(!StringUtils.isEmpty(imageURL)){
imageURL = imageURL.replaceAll(" ", "%20");
}

String uploadPicturesXML= " <?xml version=\"1.0\" encoding=\"utf-8\"?> \n"+
"<UploadSiteHostedPicturesRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\"> \n\t"+
"<RequesterCredentials> \n\t\t" +
" <ebl:eBayAuthToken xmlns:ebl=\"urn:ebay:apis:eBLBaseComponents\">"+token+"</ebl:eBayAuthToken>\n\t\t"+
"</RequesterCredentials>\n\t" +
"<ExternalPictureURL>"+imageURL.trim()+"</ExternalPictureURL>\n"+
"</UploadSiteHostedPicturesRequest>\n";
return uploadPicturesXML;
}

将getEbayPictureURL()方法返回的值如果非空就直接设置给Item.PictureDetails.PictureURL.
这样就可以实现上传多张picture到ebay。

如果你还还知道其他的方法,请发表的建议。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值