【问题标题】:Attaching file using redmine rest api使用 redmine rest api 附加文件
【发布时间】:2014-04-21 13:33:08
【问题描述】:

当我尝试将文件附加到 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);
}

问题是附加的文件被错误地保存到redmine服务器中!

【问题讨论】:

    标签: php redmine-api


    【解决方案1】:

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

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

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

    也许这对你有帮助?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-02
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多