How to upload a file without a specific content type

I just want to upload a file. But now I can only upload images.

I have it:

[HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult DownloadFile(DownloadFileModel model, string fileName, int fileId)
        {
            //var extension = Path.GetExtension(model.FileName).TrimStart('.');
            //var extensies = Seneca.SfsLib.FileSystemHelper.UploadOptInExtensions.Contains(extension);
            string customerSchema = SfsHelpers.StateHelper.GetSchema();
            TemplateLibraryEntry entry = GetTemplateLibraryEntry(model.DesignId, customerSchema);
            FileTree tree = CreateTree(model.DesignId, entry.FilePath);           
            FileInfo fileInfo = new FileInfo(tree.Files[fileId].FullPath);
            DirectoryInfo directoryInfo = new DirectoryInfo(tree.Files[fileId].FullPath);

            try {
                var fs = System.IO.File.OpenRead(fileInfo + model.FileName );
                return File(fs, "application/jpg", fileName);
            }
            catch {
                throw new HttpException(404, "Couldn't find " + model.FileName);


            }           

        }

But if I upload the file now, I see the download file every time. I mean, I do not see the file name and extensie

Thank you

+4
source share
1 answer

If you are using .NET 4.5 or later, it has built-in support to capture the MIME type directly from the file name.

MSDN Link

You can simply do:

return File(fs, System.Web.MimeMapping.GetMimeMapping(fileName), fileName);
+2
source

All Articles