Best way to send generated file to the client

I have implemented server side method makeContract, it takes an object inputData as an argument and generates docx-document as nodebuffer data. I call this method from the client on form submit.

Just for now makeContract doesn’t return anything, just writes this data to my local filesystem.

I need some way to return generated file and to send in to client, when form submission appears.

Can you give me some advise, please?

At least in our app, when we have to return a file to the client we return only the URL, and if the user wants to open it, they can click to open it (we sometimes also window.open for them).

Because we usually generate PDFs with different services and store them either on Cloudinary or S3.

2 Likes

Thanks. Good approach. But what if you need to return some private content you don’t want to be available for everyone?

got an approaching case with excel data, but did not solved by myself :stuck_out_tongue_winking_eye:

if that can help it was here https://atmospherejs.com/nicolaslopezj/excel-export

also got another with user uploaded files, but again not solved by myself :stuck_out_tongue_winking_eye:

it was based on ufs-local which can do it here https://atmospherejs.com/jalik/ufs#securing-file-access-server

you’d better wait someone can give you an answer that fit your case…