Search code examples
excelautodesk-forgeautodesk-bim360

use getObject() from forge-api npm, how to make the return result as a download link?


I am using forge-api getObject() to download the excel from BIM360 hub. I set up express sever in the backend and make the call in the frontend.

I could get the result of the object and it looks like this: enter image description here

So my question is: How can I convert the result as a download link correctly? I could download the excel, but the excel can not be opened... enter image description here

My code looks like this:

backend: enter image description here

frontend: enter image description here


Solution

  • I think all you need to modify in your backend code is to return content.body, instead of content See e.g. https://github.com/Autodesk-Forge/forge-derivatives-explorer/blob/master/routes/data.management.js#L296

    It might even be better if you generated a pre-signed URL for the file and passed that to the client. In that case, the file would not be downloaded to your server first and then to the client, but directly to the client in a single step. https://forge.autodesk.com/en/docs/data/v2/reference/http/buckets-:bucketKey-objects-:objectName-signed-POST/