2012-10-15 47 views
0

我正在使用SOAP将Drupal/PHP模块上传到Taleo(Talent Management)数据库。这适用于常规数据,如文本和日期,但不适用于文件。肥皂:上传二进制数据

手册显示文件附件的例子:

createAttachment Test Case: 
<soapenv:Header/> 
<soapenv:Body> 
<urn:createAttachment> 
<in0>webapi-5616904436472928038</in0> 
<in1>15</in1> 
<in2>test1.docx</in2> 
<in3>test1.docx</in3> 
<in4>application/vnd.openxmlformatsofficedocument. 
wordprocessingml.document</in4> 
<in5> 
<!--type: base64Binary--> 
<array>JVBERi0xLjQNJeLjz9MNCjYgMCBvYmogPDwvTGluZWFyaX==</array> 
</in5> 
</urn:createAttachment> 
</soapenv:Body> 
</soapenv:Envelope> 

所以我做了一个PHP文件是这样的:

// Send attachment 
    $fileName = drupal_get_path('module', 'taleo') . '/test.txt'; 
    $rawFile = fread(fopen($fileName, "r"), filesize($fileName)); 
    $B64File = base64_encode($rawFile); 

    $params = array(
     'in0' => $session, 
     'in1' => $candidate_id, 
     'in2' => 'test.txt', 
     'in3' => 'test.txt', 
     'in4' => 'text/plain', 
     'in5' => $B64File 
    ); 

    $client_taleo->__call('createAttachment', $params); 

当我做 “回声$ B64File” 我得到这个:RmlsZSB1cGxvYWQgd2l0aCBEcnVwYWwgIQ ==,所以文件正在被读取正确。

但我总是得到这样的错误:

错误:soapenv:Server.generalException-attBinDataArr为空。

任何想法?

回答

2

您忘了将base64数据封装在数组标签中。

<array>JVBERi0xLjQNJeLjz9MNCjYgMCBvYmogPDwvTGluZWFyaX==</array> 

像这样的东西应该工作:

$params = array(
    'in0' => $session, 
    'in1' => $candidate_id, 
    'in2' => 'test.txt', 
    'in3' => 'test.txt', 
    'in4' => 'text/plain', 
    'in5' => array('array' => $B64File) 
); 
+0

确实,但你有什么想法,PHP代码应该是什么样子?我尝试了一切:('in5'=> $ B64File,如何封装数组标签? –

+0

编辑添加了更多的代码。 – Jaif

+0

嗯,已经试过:( –

0

很显然我必须做的阵列标签的东西,这是肯定的。

上面的答案值得一个“upvote”,所以我给了它一个。但我自己找到了正确的答案......经过几秒钟的“逻辑”思考。 :)

'in5' => array('array' => $B64File)