使用redmine rest api附加文件

时间:2014-04-21 13:33:09

标签: php redmine-api

当我尝试将文件附加到redmine rest api时,我有一点问题,我正在使用php-redmine-api-master:

if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "<br>";
    }
else{
$attachement=file_get_contents($_FILES['file']['tmp_name']);
$upload = json_decode( $client->api('attachment')->upload($attachement) );
$client->api('issue')->create(array(
    'project_id'     => 12,
    'subject'        => 'test api3 (xml) 3',
    'description'    => 'test api3',
    'assigned_to_id' => 23,
    'uploads'     => array(
        array(
          'token'       => $upload->upload->token,
          'filename'    => $_FILES["file"]["name"],
          'description' => 'MyFile is better then YourFile...',
          'content_type'=> 'image/png'
        )
    )
));
print_r($client);
}

问题是,attched文件被错误地保存到redmine服务器中!

1 个答案:

答案 0 :(得分:1)

也许你的问题已经过时了。但我也曾致力于将文件附加到redmine问题上。我还没有旧的代码。但我知道上传后我的文件也被破坏了。

对我来说问题是content_type。我的解决方案很简单。我从上传表单中获取了content_type。像这样:

'content_type'=> $_FILES['file']['type']

也许这会对你有帮助吗?

相关问题