2012-01-16 164 views
2

我試圖將圖像添加到節點中。我在網上搜索,但沒有發現太多。我想我需要首先上傳圖像然後將其添加到節點,這就是爲什麼我寫了一些代碼將圖像添加到文件夾(網站/所有/默認),但徒勞。我在XmlRpcClientProtocol.cs中收到了一些錯誤 - 「無法將文件寫入目標」。使用xmlrpc將圖像添加到drupal 7節點#

使用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); 

有什麼建議嗎?

+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) 
相關問題