【问题标题】:How to get an attachment's data with the openproject API如何使用 openproject API 获取附件的数据
【发布时间】:2018-07-09 18:26:12
【问题描述】:

我目前正在尝试使用 openproject api v3 在我的网站中显示有关 openproject 工作包的数据(我正在使用带有 symfony 的 PHP。)。

获取一般数据(主题、描述、优先级等)没有问题,但我不确定如何向用户显示附件。

我尝试使用"/api/v3/work_packages/".$id."/attachments",但是返回的json中没有图片:

"_type":"Collection",
"total":1,
"count":1,
"_embedded":{
    "elements":[{
        "_type":"Attachment",
        "id":1888,"fileName":"128-128-logo.png",
        "fileSize":9583,
        "description":{"format":"plain","raw":null,"html":""},
        "contentType":"image/png",
        "digest":{"algorithm":"md5","hash":"/*-hash-here-*/"},
        "createdAt":"2018-07-09T16:49:26Z",
        "_links":{
             "self":{"href":"/api/v3/attachments/1888","title":"128-128-logo.png"},
             "author":{"href":"/api/v3/users/7","title":"User Name"},
             "container":{"href":"/api/v3/work_packages/1697","title":"Subject -\u003E Test Query OpenProject"},
             "downloadLocation":{"href":"/attachments/1888/128-128-logo.png"},
             "delete":{"href":"/api/v3/attachments/1888","method":"delete"}
        }
    }]
},
"_links":{
    "self":{"href":"/api/v3/work_packages/1697/attachments"}
}

我也试过直接链接到附件,但得到了

"_type":"Attachment",
"id":1888,
"fileName":"128-128-logo.png",
"fileSize":9583,
"description":{"format":"plain","raw":null,"html":""},
"contentType":"image/png",
"digest":{"algorithm":"md5","hash":"/*-hash-here-*/"},
"createdAt":"2018-07-09T16:49:26Z",
"_links":{
    "self":{"href":"/api/v3/attachments/1888","title":"128-128-logo.png"},
    "author":{"href":"/api/v3/users/7","title":"User Name"},
    "container":{"href":"/api/v3/work_packages/1697","title":"Subject -\u003E Test Query OpenProject"},
    "downloadLocation":{"href":"/attachments/1888/128-128-logo.png"},
    "delete":{"href":"/api/v3/attachments/1888","method":"delete"}
}

下载位置不是 API url 并返回 406 - 如果我尝试使用 img 标签 (<img src="https://XXXXXX.openproject.com/attachments/1888/128-128-logo.png">) 访问它,则未经授权

所以我想我的问题是:即使我的用户没有我的 openproject 帐户,我如何向他们显示附件?

【问题讨论】:

    标签: json openproject


    【解决方案1】:

    要在您的网站上显示附件,您必须:

    • 授予对您的 openproject 实例的匿名访问权限。
    • 在公共项目中有附件,这意味着它必须附加到公共项目的工作包、wiki 页面...

    授予对您的 openproject 实例的匿名访问权限

    在系统设置(“管理”->“系统设置”->“身份验证”(选项卡)”)中取消选中“需要身份验证”并保存。

    公开项目

    在项目设置中勾选“公共”(导航到项目后 -> “项目设置” -> “信息”(选项卡))并保存。

    您的网站只能访问附加到该现已公开项目的资源的附件。

    后果

    每个人都可以访问您的 OpenProject 实例,至少是公共项目的一部分。

    备选方案 1

    如果它是一个私人网站,并且该网站的所有访问者也将在 OpenProject 实例上拥有一个帐户,并且如果确定他们在访问该网站时将始终登录到 OpenProject,他们的浏览器将发送会话 cookie获取图像后自动到 OpenProject 实例,这将导致他们被授权获取附件。

    备选方案 2

    OP 8.0 发布后,API 客户端将能够下载附件。然后带有 API 密钥的脚本可以下载感兴趣的附件并将它们存储在您的网站可以访问的位置。然后网站访问者将直接从网站获取附件。

    【讨论】:

    • 谢谢!我希望有一种方法可以在没有登录或公共项目的情况下访问它,但我想没有办法:(
    猜你喜欢
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多