Skip to content
Advertisement

Download file with original file name

In my project I am uploading a file. While uploading, I am saving its original file name and extension in a database and saving that file with some GUID on server, generated GUID is also stored in database along with file name and extension.

For example-

-File name for uploading is questions.docx

-Then orignalFileName will be “questions”

-FileExtension will be “.docx”

-File be get uploaded with file name as “0c1b96d3-af54-40d1-814d-b863b7528b1c”

Uploading is working fine..but when I am downloading some file it gets downloaded with file name as the GUID in above case its “0c1b96d3-af54-40d1-814d-b863b7528b1c”.
How can I download a file with its original file name i.e “questions.docx”.

Code Added

JavaScript

Is this code is perfect?

Advertisement

Answer

You should set your origin file name into the response header, like below:

JavaScript

Hope to help you:)

Advertisement