How to tell Google Chrome to change the extension of the file in NodeJS?

res.setHeader('Content-Type', 'application/pdf')

this will automatically download or show the file in pdf format directly.

If We want to change name of the file if we are getting random names from the ID we got which gives us a random number always we can do that just by entering this small code

res.setHeader('Content-Disposition', 'attachment; filename="' + invoiceName + '"')


attachment will open our file in new window

if we use inline instead of attachment our file will open in the same tab. and it will not start downloading in this but in case of attachment it will automatically start downloading our file.

res.setHeader('Content-Disposition', 'inline; filename="' + invoiceName + '"')




Now Restricting our File Access for other Clients



0 views0 comments

Recent Posts

See All

SQL UNION Operator UNION operator is used to combine the results of two or more SELECT statements Every SELECT statement within UNION must have the same number of columns The columns must also have si

JOIN clause is used to combine rows from two or more tables. INNER JOIN === selects records that have matching values in both tables SELECT Orders.OrderID, Customers.CustomersID, Orders.OrdersDate FRO