【问题标题】:Autodesk Forge - Reality Capture Issue - Specified Photoscene ID doesn't exist in the databaseAutodesk Forge - 现实捕捉问题 - 数据库中不存在指定的 Photoscene ID
【发布时间】:2022-01-23 17:33:14
【问题描述】:

在创建场景后,我正在尝试将我的文件作为表单数据上传。但我总是收到错误“指定的 Photoscene ID 在数据库中不存在”(之前直接创建)。

我的上传功能:

// Upload Files
async function uploadFiles(access_Token, photoSceneId, files) {
    try {

        const params = new URLSearchParams({
            'photosceneid': photoSceneId,
            'type': 'image',
            'file': files
        })

        const headers = Object.assign({
            Authorization: 'Bearer ' + access_Token,
            'Content-Type': 'multipart/form-data' }, 
            files.getHeaders()
        )
        
        let resp = await axios({
            method: 'POST',
            url: 'https://developer.api.autodesk.com/photo-to-3d/v1/file',
            headers: headers,
            data: params

        })
        let data = resp.data;
        return data;
    } catch (e) {
        console.log(e);
    }
};

我也尝试了一些变种,例如将 photosceneId 添加到表单数据(form.append(..),但也不起作用。

感谢任何有用的建议。提前谢谢。

【问题讨论】:

    标签: node.js axios multipartform-data autodesk-forge autodesk-realitycapture


    【解决方案1】:

    这里可能有两个问题。 首先,我不确定,因为我没有将 URLSearchParams 作为 POST 请求的“打包程序”的经验。这可能是您收到“数据库中不存在指定的 Photoscene ID”错误的原因 - 可能是使用 URLSearchParams 序列化数据的方式不兼容。

    我敢肯定,第二个问题与您提交文件的方式有关。 根据to documentation,你必须一个一个地传递文件,比如

      "file[0]=http://www.autodesk.com/_MG_9026.jpg" \
      "file[1]=http://www.autodesk.com/_MG_9027.jpg"
    

    而不仅仅是将数组传递给“文件”字段。

    话虽如此,试试这个方法:

    var axios = require('axios');
    var FormData = require('form-data');
    var fs = require('fs');
    var data = new FormData();
    var TOKEN = 'some TOKEN';
    const photoSceneID = 'some_photoscene_id';
    
    data.append('photosceneid', photoSceneID);
    data.append('type', 'image');
    data.append('file[0]', fs.createReadStream('/C:/TEMP/Example/DSC_5427.JPG'));
    data.append('file[1]', fs.createReadStream('/C:/TEMP/Example/DSC_5428.JPG'));
    data.append('file[2]', fs.createReadStream('... and so on ...'));
    
    var config = {
      method: 'post',
      url: 'https://developer.api.autodesk.com/photo-to-3d/v1/file',
      headers: { 
        'Content-Type': 'application/x-www-form-urlencoded', 
        'Authorization': 'Bearer ' + TOKEN, 
      },
      data : data
    };
    
    axios(config)
    .then(function (response) {
      console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
      console.log(error);
    });

    另外,我始终建议不要直接跳入代码,而是先使用 PostmanInsomnia 等应用程序检查工作流程,然后在验证工作流程后(创建照片场景,所有图像均已正确上传并等等),你可以把它翻译成代码。

    this blogpost 的末尾,您会找到指向已经创建的 Postman 收藏的链接,但我强烈建议您建立自己的收藏,作为学习步骤的一部分。

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 2019-10-26
      • 2021-01-16
      • 1970-01-01
      • 2016-12-08
      • 2018-05-21
      • 1970-01-01
      • 2021-10-16
      • 2020-02-21
      相关资源
      最近更新 更多