I am integrating Forge Api in my NodeJs application. All other Api works e.g authentication , creating bucket and translation a model.When I redirect to the html page to view my model it gives the 404 error..I have been stuck on this.
Below is the code and images attached.Authentication and bucket creation Api's skipped in the below code..
Folder structure is
->server
-->app.js
-->viewer.html
App.js
app.post('/api/forge/datamanagement/bucket/upload/uploads/:filename', function (req, res) {
console.log(req.params.filename);
console.log("Token",access_token)
var fs = require('fs'); // Node.js File system for reading files
fs.readFile(`./uploads/${req.params.filename}`, function (err, filecontent) {
console.log(filecontent)
Axios({
method: 'PUT',
url: 'https://developer.api.autodesk.com/oss/v2/buckets/' + encodeURIComponent(bucketKey) + '/objects/' + encodeURIComponent(req.params.filename),
headers: {
Authorization: 'Bearer ' + access_token,
'Content-Disposition': req.params.filename,
'Content-Length': filecontent.length
},
data: filecontent
}).then(function (response) {
// Success
console.log(response);
console.log("IdUrn ====>>>>>>>"+ response.data.objectId)
var urn = response.data.objectId.toBase64();
console.log("In Response")
res.redirect('/api/forge/modelderivative/' + urn);
}).catch(function (error) {
// Failed
console.log(error.message);
res.send(error.message);
});
});
});
app.get('/api/forge/modelderivative/:urn', function (req, res) {
console.log("urrrr",req.params.urn)
var urn = req.params.urn;
var format_type = 'svf';
var format_views = ['2d', '3d'];
Axios({
method: 'POST',
url: 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job',
headers: {
'content-type': 'application/json',
Authorization: 'Bearer ' + access_token
},
data: JSON.stringify({
'input': {
'urn': urn
},
'output': {
'formats': [
{
'type': format_type,
'views': format_views
}
]
}
})
})
.then(function (response) {
// Success
console.log("Translated=============>>>",response);
res.redirect('/viewer.html?urn=' + urn);
})
.catch(function (error) {
// Failed
console.log(error);
// res.send(error.message);
});
});
Response in the network Tab