1

我刚开始使用文档使用 API,但在上传文件时遇到了问题。我没有从对上传文件的 api 调用中得到任何响应。我尝试了多种文件类型,但没有成功。这是我的 API 调用:

$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>';
}

根据文档,我应该收到一个包含文件上传代码的响应,但我没有收到任何响应,甚至没有收到验证错误。它也不会抛出异常。我对任何其他请求都没有问题,所以我认为这不是身份验证问题。谁能帮我弄清楚我做错了什么?

4

2 回答 2

1

有同样的问题,这是我解决它的方法:

从 SDK 中的 post 方法内部:

if (is_array($file)) {
    list($path, $mime_type) = $file;
}

来自 php.net:

In PHP 5, list() assigns the values starting with the right-most parameter.
In PHP 7, list() starts with the left-most parameter.

我正在使用 php 5.6,所以我交换了:

['/path/to/file.png' => 'image/png']

至:

['image/png' => '/path/to/file.png']

现在按预期工作。

于 2016-09-01T11:49:17.790 回答
1

为了上传文件,您应该传递一个文件路径数组或路径 - 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在本例中)上的文件存在且可读的情况。

于 2016-03-17T22:16:34.227 回答