使用PHPSDK的活动协作文件上载
我刚开始使用API文档,上传文件时遇到问题。我没有收到上传文件的api调用的响应。我尝试了多种文件类型,但没有成功。以下是我的API调用:使用PHPSDK的活动协作文件上载,php,api,activecollab,Php,Api,Activecollab,我刚开始使用API文档,上传文件时遇到问题。我没有收到上传文件的api调用的响应。我尝试了多种文件类型,但没有成功。以下是我的API调用: $client = new \ActiveCollab\SDK\Client($token); try { $response = $client->post('upload-files',[ [ 'test-file.txt', 'text\/plain' ]
$client = new \ActiveCollab\SDK\Client($token);
try {
$response = $client->post('upload-files',[
[
'test-file.txt',
'text\/plain'
]
]);
echo $response->getBody();
} catch(AppException $e) {
print $e->getMessage() . '<br><br>';
}
$client=new\ActiveCollab\SDK\client($token);
试一试{
$response=$client->post('upload-files'[
[
'测试文件.txt',
“文本\/plain”
]
]);
echo$response->getBody();
}捕获(除$e外){
打印$e->getMessage()。
;
}
根据文档,我应该会收到一个包含
文件上传代码,但我没有收到响应,甚至没有验证错误。它也不会抛出异常。我没有遇到任何其他请求的问题,所以我认为这不是身份验证问题。谁能帮我找出我做错了什么 为了上传文件,您应该传递一组文件路径或路径MIME类型对作为客户端
post
方法的第三个参数:
$response = $client->post('upload-files', [], ['/path/to/file.png']);
$response = $client->post('upload-files', [], ['/path/to/file.png' => 'image/png']);
只有在给定路径(本例中为
/path/to/file.png
)上的文件存在且可读时,此方法才有效。也有同样的问题,下面是我解决问题的方法:
从SDK中的post方法内部:
从php.net:
我使用的是PHP5.6,所以我交换了:
['/path/to/file.png' => 'image/png']
['image/png' => '/path/to/file.png']
至:
['/path/to/file.png' => 'image/png']
['image/png' => '/path/to/file.png']
现在一切正常。感谢您的回复!尽管如此,当我尝试第一种方式时,我还是遇到了一些麻烦,
$response=$client->post('upload-files',[],['images/testimage'])
我在Client.php第222行中得到异常ErrorException:文件“images/test image”不可读
。当我尝试第二种方法时,$response=$client->post('upload-files',[],['images/test-image.jpg'=>'image/jpeg'])
我在Client.php第222行得到响应ErrorException:文件'image/jpeg'不可读
,知道我做错了什么吗?我认为该文件很好,它在我们的应用程序中使用,没有问题。您没有提供文件的有效路径。我建议您使用sile系统上文件的绝对路径:/tmp/file-that-I-want-to-upload.jpg
或c:\MyFolder\MyFile.jpg
。我已更新了答案,以明确您尝试上载的文件需要存在于文件系统上。