How to create a product image on Magento Api using Ruby

社会主义新天地 提交于 2019-12-25 03:12:20

问题


I am try to upload a image on magento API using Ruby.

This is my code:

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')

When I run this code I got this error:

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

Is there any solution for my problem?

Thanks


回答1:


When i encode the image, it put the newline character at the end of line.This newline character create the problem. Magento needs the encoded image without the newline character. So remove the newline character and run the code again it will work.

Its Works for me!



来源:https://stackoverflow.com/questions/5752735/how-to-create-a-product-image-on-magento-api-using-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!