2011-04-22 85 views
0

我嘗試使用Ruby在magento API上上傳圖像。如何使用Ruby在Magento Api上創建產品圖像

這是我的代碼:

require 'rubygems' 
require 'soap/wsdlDriver' 
require 'base64' 

WSDL_URL = 'http://teeshop.chandru/api/v2_soap/?wsdl=1' 

soap = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver 

session = soap.login('*********','*********') 


a = File.read('image/CP0760-01.jpg') 
enc = Base64.encode64(a) 

create_image = { 'file' => {"name" => "CP0760-01.jpg", "content" => enc,"mime" => 'image/jpeg'}, "label" => "kids cloths","position" => 0, "types" => ["image,""small_image", "thumbnail" ], "exclude" => 0 } 

product_image = soap.call('catalogProductAttributeMediaCreate',session,'CP0760 (P.34)',creeate_image,1,'sku') 

當我運行這段代碼,我得到這個錯誤:

The image contents is not valid base64 data. (SOAP::FaultError)

是否有我的問題的任何解決方案?

感謝

回答

0

當我對圖像進行編碼,它把換行符在line.This結束換行符創建問題。 Magento需要不帶換行符的編碼圖像。 因此,刪除換行符並再次運行代碼,它將起作用。

它適合我!

相關問題