Unexpected line error when piping .obj from my server to OBJLoader

I have an .obj file created with Tinkercad that I wish to use to create a three js model. Here’s a snipet of the .obj file:

# Object Export From Tinkercad Server 2015

mtllib obj.mtl

o obj_0
v -178.5 		-379.374 		1
v -178.5 		-304.374 		1
v -298.5 		-304.374 		1

If I try loading from a local copy of the file I have no problems…

const model = useLoader(OBJLoader, “/64906b69b76403f8905edbcd.obj”);

but my files are maintained on a remote server (Digital Ocean Spaces) and if I try to load directly from the client then I get a CORS error because OBJLoader does not allow me to set Access-Control-Allow-Headers.

So, I am proxying via my own node js server running express and piping the result back to the client.

Client side:

const model = useLoader(OBJLoader, /api/model/${objUrl});

Server side:

  app.get("/api/model/:filename", async function(req, res) {
    const response = await fetch(`${process.env.SPACES_CDN_ENDPOINT}/models/${req.params.filename}`);
    response.body.pipe(res)
  });

However, now I get the following error:

Model.js:24 THREE.OBJLoader: Unexpected line: "<?xml version="1.0" encoding="UTF-8"?><Error><Code>AccessDenied</Code><Message></Message><BucketName>mycamino3d</BucketName><RequestId>tx00000329fb62fdc65f119-0065a561d0-cd0c417a-fra1b</RequestId><HostId>cd0c417a-fra1b-fra1-zg02</HostId></Error>"

To confirm that the data is being piped correctly, I have tested displaying it. Looks to be an exact copy of the original file:

Can anyone suggest a solution, please? Thanks!

Looks like the obj loader isn’t allowed access to that file for some reason… that’s what that error means… it’s trying to parse the error response xml as an obj file.

<Error>
<Code>AccessDenied</Code>
<Message></Message>
<BucketName>mycamino3d</BucketName>
<RequestId>tx00000329fb62fdc65f119-0065a561d0-cd0c417a-fra1b</RequestId>
<HostId>cd0c417a-fra1b-fra1-zg02</HostId>
</Error>

Thanks @manthrax. Yes, it looks like the problem is at the server end. I’ve sorted it out now.

1 Like

Excellent! :smiley: