dougan7657 2012-12-04 13:00
浏览 64
已采纳

如何使用magento api创建图像

I'm trying to use the magento api to create an image, but it's failing with the message

SoapFault exception: [104] Cannot create image.

This is not a helpful error message! What does this mean? Why is it doing this? How do I create an image, using the magento api?

This is my code:

$client = new SoapClient($wsdlurl);
$sessionId = $client->login($user, $key);
$file = array(
    'content' =>
    base64_encode(file_get_contents($filename)),
    'mime' => 'image/jpeg',
    'name' => 'newfile.jpg'
);

$result = $client->call(
    $sessionId,
    'catalog_product_attribute_media.create',
    array(
        $productId,
        array('file'=>$file, 'label'=>'new_test_label', 'position'=>'100', 'types'=>array('thumbnail'), 'exclude'=>0)
    )
);

What am I doing wrong?

  • 写回答

2条回答 默认 最新

  • doujiu3768 2012-12-04 13:39
    关注

    I found the solution. The directory it was trying to put the image in (.../media/catalog/product/) did not have permissions set to allow new folders to be created in it.

    For the benefit of others, though, I did find a couple of useful things: First, filesystem operations are carried out by ./lib/Varien/Io/File.php, which has it's own wrappers for cd, mkdir, etc, which throw really vague exceptions if they fail.

    The directory creation was occurring in Mage_Catalog_Model_Product_Attribute_Backend_Media->_moveImageFromTmp

    which was called from ./app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api.php which handles all the image api calls, e.g. create, update, remove, etc.

    So, if you have the same problem and it's not a permissions issue... you now know where to put your debug code ;).

    Oh yeah, and if you want to output an error message, you can't just echo or die; you need to throw an exception, which will get caught by Mage_Catalog_Model_Product_Attribute_Media_Api, which will then call $this->_fault to send it to the client.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大