`
jiangduxi
  • 浏览: 456608 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

上传多张图片至ebay的总结

 
阅读更多
   最近需要帮助ebay sales部门实现能够针对一种产品上传多张图片,在查看Ebay Call Reference,原以为找一个ebay Call 就能够搞定,这次算了思路有问题。还好jack的代码给很大的帮助。下面看看Call Reference中关于UploadSiteHostedPictures。这个就是用于将图片上传到ebay的关键。
引用

   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.

  这段描述主要理解了,这个不支持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。

如果你还还知道其他的方法,请发表的建议。
1
0
分享到:
评论

相关推荐

    30 Business cases printversion

    该公司拥有超过 39 个领域的专家团队,用户只需上传物品的照片,就能在两天内获得一份完整的鉴定报告。 **关键数据:** - **员工数量:** 50 人 - **总部位置:** 英国伦敦 - **成立时间:** 2009 年 - **业务范围...

    PHP经典实例

    - **文件上传与下载**:允许用户上传图片、文档等文件,并提供下载服务。 - **数据统计分析**:利用PHP进行数据抓取、清洗、统计分析并展示结果。 #### 六、学习资源推荐 虽然题目给出的部分内容主要是关于各种...

    大数据应用27.pptx

    例如,社交媒体平台如Facebook、Twitter每天都在生成海量的用户互动数据,电子商务网站如淘宝、eBay的交易数据也持续膨胀。这些数据的总量在短短几年内就翻了数倍,甚至达到PB、EB的级别。 其次,“多样性”...

    基于Web的校园跳蚤市场交易系统的设计与实现(论文+源码)-kaic.docx

    - **商品发布**:用户可以上传商品图片、填写商品描述、设置价格等信息,并提交审核。 - **商品搜索与筛选**:用户可根据关键词、类别等条件搜索商品,并进行筛选排序。 - **商品购买**:用户选定商品后,可联系卖家...

    JAVA网上拍卖系统的设计与实现(源代码+论文).zip

    - **商品发布**:卖家可以上传商品图片,填写描述,设置起拍价和拍卖时间。 - **竞拍过程**:买家可以查看商品,参与出价,系统自动检查出价合法性(高于当前最高价)并记录。 - **拍卖结束与交易**:拍卖结束后...

    Web Auction-开源

    商品图片的上传和展示功能增强了用户的购物体验,使拍卖物品更直观、更具吸引力。 3. **竞拍机制**: 竞拍过程可能采用增价拍卖模式,即每次出价必须高于当前最高出价并符合最小出价增量。系统会实时更新商品状态...

    BInventory-开源

    - **多平台整合**:对于eBay等电商平台的卖家,BInventory可以无缝对接,实现库存同步,避免超卖情况,提高销售效率。 - **自定义展示**:用户可以根据自己的需求定制商品展示页面,以吸引潜在买家。 - **安全与...

    计算机科学与技术_基于SSM的校园闲置物品共享平台的设计与实现.docx

    - 用户可以上传商品图片、填写商品描述、设置价格等信息进行发布。 - 支持对已发布的商品进行编辑、删除等操作。 3. **搜索模块**: - 支持关键字搜索,用户可以根据商品名称、类别等信息进行精确或模糊搜索。 ...

Global site tag (gtag.js) - Google Analytics