【问题标题】:Adding image into a drupal 7 node using xmlrpc c#使用xmlrpc c#将图像添加到drupal 7节点中
【发布时间】:2012-02-11 17:53:44
【问题描述】:

我正在尝试将图像添加到节点中。我在网上搜索但没有找到太多。我想我需要先上传图像然后将其添加到节点中,这就是为什么我编写了一些代码将图像添加到文件夹(站点/所有/默认)但徒劳无功。我在 XmlRpcClientProtocol.cs 中遇到一些错误 - “无法将文件写入目标”。

使用 file.create 方法。

     XmlRpcStruct file = new XmlRpcStruct();

        file.Add("file", encodedData);
        file.Add("filename", filename);
        file.Add("filepath", "sites/default/files/" + filename);
        file.Add("filesize", filestream.Length);
        file.Add("timestamp", DateTime.Now.ToShortTimeString());

     drupal.FileSave(file);

有什么建议吗?

【问题讨论】:

    标签: c# drupal xml-rpc image-uploading


    【解决方案1】:

    在 Python 中:

    with open(filepath + name_, 'rb') as f:
        img = base64.b64encode(f.read())
        size = os.path.getsize(filepath + name_)
        file = {'methodCall': 
                 {'params': 
                   {'param': 
                     {'struct': 
                       {'member': [
                         {'name': 'filesize', 'value':{'string': str(size)}}, 
                         {'name': 'filename', 'value':{'string': str(filepath + name_)}},
                         {'name': 'file', 'value':{'string': str(img)}}, 
                         {'name': 'filepath', 'value':{'string': 'public://product_image/'+str(name_)}}, 
                         ]
                       }
                     }
                   }, 
                   'methodName': 'file.create'
                 }
               }   
        xml = dict2xml.dict2xml(file)
    

    【讨论】:

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