【问题标题】:How to create a product image on Magento Api using Ruby如何使用 Ruby 在 Magento Api 上创建产品图像
【发布时间】: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)

我的问题有什么解决办法吗?

谢谢

【问题讨论】:

    标签: ruby soap magento


    【解决方案1】:

    当我对图像进行编码时,它会将换行符放在行尾。这个换行符会产生问题。 Magento 需要没有换行符的编码图像。 所以删除换行符并再次运行代码就可以了。

    它对我有用!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多