You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用APS API搜索PDF时返回的webview href链接失效问题咨询

问题解决:APS搜索接口返回的webView链接失效

APS搜索接口返回的webView.href属于短期预签名链接,有效期通常为15分钟左右,且当文件版本更新、权限发生变动时,旧链接会直接失效——这就是你遇到部分链接提示“无法查看文件”但文件实际存在的原因。

以下两种方法可以获取当前有效的webView链接:

方案1:调用文件详情接口获取实时链接

对每个搜索到的文件ID,单独调用项目文件详情接口,该接口返回的webView链接是实时生成的有效链接。

修改后的代码示例:

const searchResponse = await axios({
    method: 'get',
    url: `https://developer.api.autodesk.com/data/v1/projects/${dm_project_id}/folders/${rootFolderID}/search?filter[fileType]=pdf`,
    headers: {
        'Authorization': `Bearer ${req.session.token}`
    }
});

// 批量请求文件详情,获取有效webView链接
const simplifiedList = await Promise.all(searchResponse.data.data.map(async item => {
    const detailRes = await axios({
        method: 'get',
        url: `https://developer.api.autodesk.com/data/v1/projects/${dm_project_id}/items/${item.id}`,
        headers: {
            'Authorization': `Bearer ${req.session.token}`
        }
    });
    return {
        id: item.id,
        displayName: item.attributes.displayName,
        createTime: item.attributes.createTime,
        createUserName: item.attributes.createUserName,
        lastModifiedTime: item.attributes.lastModifiedTime,
        lastModifiedUserName: item.attributes.lastModifiedUserName,
        webViewHref: detailRes.data.data.links.webView.href
    };
}));

console.log(simplifiedList);

方案2:直接构造永久有效链接

无需额外调用API,直接用项目ID和文件ID构造固定格式的链接,该链接会自动跳转至文件的最新有效预览页面:

https://autodesk360.autodesk.com/gallery/${dm_project_id}/${item_id}/details

简化后的map逻辑:

const simplifiedList = searchResponse.data.data.map(item => {
    return {
        id: item.id,
        displayName: item.attributes.displayName,
        createTime: item.attributes.createTime,
        createUserName: item.attributes.createUserName,
        lastModifiedTime: item.attributes.lastModifiedTime,
        lastModifiedUserName: item.attributes.lastModifiedUserName,
        webViewHref: `https://autodesk360.autodesk.com/gallery/${dm_project_id}/${item.id}/details`
    };
});

该方案避免了额外的API请求开销,推荐优先使用。

内容的提问来源于stack exchange,提问作者Jon Haider

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 23:42:46