RealityCapture API: 启动处理失败
RealityCapture API: Failed to initiate processing
我正在阅读 Autodesk forge 在 [RealityCapture API][1] 上提供的教程。
我想开发一个应用程序,可以将我 phone 拍摄的照片发送到 Autodesk forge 服务器并获得 return 3D 模型。
但是我卡在了处理的初始化阶段。
我的浏览器出现以下错误消息 window:
At least three images are required to process the Photoscene
并且在我的 Node.js 命令中提示以下错误:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:561:11)
at ServerResponse.header (C:\git\recap-walkthrough-photo.to.3d\node_modules\express\lib\response.js:771:10)
at ServerResponse.send (C:\git\recap-walkthrough-photo.to.3d\node_modules\express\lib\response.js:170:12)
at C:\git\recap-walkthrough-photo.to.3d\start.js:171:17
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
code: 'ERR_HTTP_HEADERS_SENT'
}
(node:45332) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:561:11)
at ServerResponse.header (C:\git\recap-walkthrough-photo.to.3d\node_modules\express\lib\response.js:771:10)
at ServerResponse.send (C:\git\recap-walkthrough-photo.to.3d\node_modules\express\lib\response.js:170:12)
at C:\git\recap-walkthrough-photo.to.3d\start.js:176:17
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:45332) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:45332) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我只修改了文件[]路径和源代码中的'content-type':
// Route /api/forge/recap/photoscene/upload
// Adds one or more files to a photoscene.
app.get('/api/forge/recap/photoscene/upload', function (req, res) {
var photosceneId = req.query.photosceneid;
Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/photo-to-3d/v1/file',
headers: {
'content-type': 'multipart/form-data',
'Authorization': 'Bearer ' + access_token
},
data: querystring.stringify({
photosceneid: photosceneId,
type: 'image',
'file[0]': 'C:\Dataset\FlowerPot210527_082430.jpg',
'file[1]': 'C:\Dataset\FlowerPot210527_082459.jpg',
'file[2]': 'C:\Dataset\FlowerPot210527_082513.jpg',
'file[3]': 'C:\Dataset\FlowerPot210527_082525.jpg',
'file[4]': 'C:\Dataset\FlowerPot210527_082832.jpg',
'file[5]': 'C:\Dataset\FlowerPot210527_082937.jpg',
'file[6]': 'C:\Dataset\FlowerPot210527_082944.jpg'
})
})
.then(function (response) {
// Success
console.log(response);
if (response.data.Error) {
res.send(response.data.Error.msg);
}
console.log(JSON.stringify(response.data.Files));
var nextLink = '/api/forge/recap/photoscene/process?photosceneid=' + photosceneId;
res.send('<p>Files added to photoscene!</p><a href="' + nextLink + '">Begin processing photoscene</a>');
})
.catch(function (error) {
// Failed
console.log(error);
res.send('Failed to upload files to photoscene');
});
});
如何验证我的图片是否已成功上传?
[1]: https://forge.autodesk.com/developer/learn/recap-app/overview
请注意,将文件上传到 ReCap 服务时不能使用本地文件系统路径。您基本上是在告诉 ReCap 服务器“从 C:\Dataset\FlowerPot... 下载这 7 个文件”,但服务器显然无法访问这些文件。
要解决此问题,您必须:
- 通过一些 public URL 访问您的照片(例如,通过将它们上传到临时 S3 存储桶),或
- 将图片的实际内容添加到axios请求中,例如像这样:
const FormData = require('form-data');
// ...
app.get('/api/forge/recap/photoscene/upload', function (req, res) {
// ...
const formData = new FormData();
formData.append('file[0]', someImageBuffer0);
formData.append('file[1]', someImageBuffer1);
formData.append('file[2]', someImageBuffer2);
formData.append('file[3]', someImageBuffer3);
Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/photo-to-3d/v1/file',
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': 'Bearer ' + access_token
},
formData
})
// ...
});
顺便说一句。 Cannot set headers after they are sent to the client
错误是由 Express.js 框架发出的,表明您的代码中某处您已经发送了对请求的响应,现在您正尝试向同一响应发送一些额外的数据不被允许。在这种特定情况下,它可能是文件上传的“成功”分支,您可能会在其中向客户端发送一些错误信息(res.send(response.data.Error.msg);
),但稍后您会再次向同一响应发送另一条消息( res.send('<p>Files added to photoscene!</p><a href="' + nextLink + '">Begin processing photoscene</a>');
)。将错误信息发送给客户端后,考虑使用return
语句,这样就不会在响应中发送其他数据了。
我正在阅读 Autodesk forge 在 [RealityCapture API][1] 上提供的教程。
我想开发一个应用程序,可以将我 phone 拍摄的照片发送到 Autodesk forge 服务器并获得 return 3D 模型。
但是我卡在了处理的初始化阶段。 我的浏览器出现以下错误消息 window:
At least three images are required to process the Photoscene
并且在我的 Node.js 命令中提示以下错误:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:561:11)
at ServerResponse.header (C:\git\recap-walkthrough-photo.to.3d\node_modules\express\lib\response.js:771:10)
at ServerResponse.send (C:\git\recap-walkthrough-photo.to.3d\node_modules\express\lib\response.js:170:12)
at C:\git\recap-walkthrough-photo.to.3d\start.js:171:17
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
code: 'ERR_HTTP_HEADERS_SENT'
}
(node:45332) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:561:11)
at ServerResponse.header (C:\git\recap-walkthrough-photo.to.3d\node_modules\express\lib\response.js:771:10)
at ServerResponse.send (C:\git\recap-walkthrough-photo.to.3d\node_modules\express\lib\response.js:170:12)
at C:\git\recap-walkthrough-photo.to.3d\start.js:176:17
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:45332) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:45332) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我只修改了文件[]路径和源代码中的'content-type':
// Route /api/forge/recap/photoscene/upload
// Adds one or more files to a photoscene.
app.get('/api/forge/recap/photoscene/upload', function (req, res) {
var photosceneId = req.query.photosceneid;
Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/photo-to-3d/v1/file',
headers: {
'content-type': 'multipart/form-data',
'Authorization': 'Bearer ' + access_token
},
data: querystring.stringify({
photosceneid: photosceneId,
type: 'image',
'file[0]': 'C:\Dataset\FlowerPot210527_082430.jpg',
'file[1]': 'C:\Dataset\FlowerPot210527_082459.jpg',
'file[2]': 'C:\Dataset\FlowerPot210527_082513.jpg',
'file[3]': 'C:\Dataset\FlowerPot210527_082525.jpg',
'file[4]': 'C:\Dataset\FlowerPot210527_082832.jpg',
'file[5]': 'C:\Dataset\FlowerPot210527_082937.jpg',
'file[6]': 'C:\Dataset\FlowerPot210527_082944.jpg'
})
})
.then(function (response) {
// Success
console.log(response);
if (response.data.Error) {
res.send(response.data.Error.msg);
}
console.log(JSON.stringify(response.data.Files));
var nextLink = '/api/forge/recap/photoscene/process?photosceneid=' + photosceneId;
res.send('<p>Files added to photoscene!</p><a href="' + nextLink + '">Begin processing photoscene</a>');
})
.catch(function (error) {
// Failed
console.log(error);
res.send('Failed to upload files to photoscene');
});
});
如何验证我的图片是否已成功上传?
[1]: https://forge.autodesk.com/developer/learn/recap-app/overview
请注意,将文件上传到 ReCap 服务时不能使用本地文件系统路径。您基本上是在告诉 ReCap 服务器“从 C:\Dataset\FlowerPot... 下载这 7 个文件”,但服务器显然无法访问这些文件。
要解决此问题,您必须:
- 通过一些 public URL 访问您的照片(例如,通过将它们上传到临时 S3 存储桶),或
- 将图片的实际内容添加到axios请求中,例如像这样:
const FormData = require('form-data');
// ...
app.get('/api/forge/recap/photoscene/upload', function (req, res) {
// ...
const formData = new FormData();
formData.append('file[0]', someImageBuffer0);
formData.append('file[1]', someImageBuffer1);
formData.append('file[2]', someImageBuffer2);
formData.append('file[3]', someImageBuffer3);
Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/photo-to-3d/v1/file',
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': 'Bearer ' + access_token
},
formData
})
// ...
});
顺便说一句。 Cannot set headers after they are sent to the client
错误是由 Express.js 框架发出的,表明您的代码中某处您已经发送了对请求的响应,现在您正尝试向同一响应发送一些额外的数据不被允许。在这种特定情况下,它可能是文件上传的“成功”分支,您可能会在其中向客户端发送一些错误信息(res.send(response.data.Error.msg);
),但稍后您会再次向同一响应发送另一条消息( res.send('<p>Files added to photoscene!</p><a href="' + nextLink + '">Begin processing photoscene</a>');
)。将错误信息发送给客户端后,考虑使用return
语句,这样就不会在响应中发送其他数据了。