【发布时间】:2011-04-22 06:09:23
【问题描述】:
我正在尝试使用 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')
当我运行这段代码时,我得到了这个错误:
图像内容不是有效的 base64 数据。 (SOAP::FaultError)
我的问题有什么解决办法吗?
谢谢
【问题讨论】: