使用xmlrpc c#将图像添加到drupal 7节点

时间:2012-01-16 20:39:14

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

我正在尝试将图像添加到节点中。我在网上搜索但没有找到太多。我想我需要首先上传图像然后将其添加到节点中,这就是为什么我写了一些代码将图像添加到文件夹(sites / all / default)但是徒劳无功。我在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);

有什么建议吗?

1 个答案:

答案 0 :(得分: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)